I need some help, I am learning php through wordpress, so I don’t really know the php basic and don’t really know wordpress either.
so I have this shortcode function:
function links( $atts, $content = null ){
$args = shortcode_atts( array(
's' => '',
'l' => '',
), $atts);
$api = file_get_contents('API URL'.$args['l']);
$result1 = '<a href="'. $api .'">'. $args['s'] .'</a>';
$result2 = '<a href="'. $args['l'] .'">'. $args['s'] .'</a>';
return THIS IS I NEED THE IF LOGGED IN SHOWS $result2 AND THE OTHERWISE
}
add_shortcode ('link', 'links');
the shortcode is already written in custom meta box group text area from foreach.
[link s="Google" l="https://google.com"]
I write this in single.php
echo do_shortcode($linkx['link_box']);
thank you in advance.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Use is_user_logged_in() in the logic to decide what to return.
See https://developer.wordpress.org/reference/functions/is_user_logged_in/
I assume $linkx['link_box'] contains the shortcode.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0