最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

shortcode with conditional results if logged in

programmeradmin2浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

Use 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.

发布评论

评论列表(0)

  1. 暂无评论