shortcode with conditional results if logged in

Question

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.

0
Tiyo 2 months 0 Answers 20 views 0

Leave an answer