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=";]
I write this in single.php
echo do_shortcode($linkx['link_box']);
thank you in advance.
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"]
I write this in single.php
echo do_shortcode($linkx['link_box']);
thank you in advance.
Share Improve this question asked Nov 15, 2020 at 14:52 TiyoTiyo 636 bronze badges1 Answer
Reset to default 1Use is_user_logged_in()
in the logic to decide what to return.
See https://developer.wordpress/reference/functions/is_user_logged_in/
I assume $linkx['link_box']
contains the shortcode.