WordPress.org

Ready to get started?Download WordPress

Forums

Global Content Blocks
[resolved] Shortcode in block only works sometimes (2 posts)

  1. Ricki
    Member
    Posted 1 year ago #

    I am trying to insert shortcode into a content block. The shortcode is setup by a plugin called Wishlist Member.

    The shortcodes that do not use enclosing content work just fine in GCB, but any shortcodes that have enclosing content do not.

    Shortcodes with enclosing content appear on the front-end.

    This shortcode works just fine.
    [wlm_loginform]

    This shortcodes does not work.
    [nonmember]Display this message to non-members[/nonmember]

    The PHP code I have inserted in GCB is:

    if (is_user_logged_in()) {
         $message = do_shortcode('[contentblock id=3]');
         echo do_shortcode('[nonmember]' . $message . '[/nonmember]');;
    } else {
         echo do_shortcode('[contentblock id=2]');
    }

    http://wordpress.org/extend/plugins/global-content-blocks/

  2. benz1
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Ricki,

    From my developer:

    The example provided is not very clear, but I have a suggestion of code that might help you:
    you can create a PHP block, and use this code in it:

    if(is_user_logged_in()) {
    echo "you are logged in! [caption] Hello there [/caption]";
    } else {
    echo "you are not logged in! [caption] Please Login [/caption]";
    }

    This should work as intended. If would want to nest shortcodes even further, you could try embedding other content blocks (that would run their inner shortcodes). Beware of embedding a content block in itself, you would go into an infinite loop!

    Hope all of this is clear. If not, let me know exactly what you want to achieve, and we will help you further.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.