Global Content Blocks
[resolved] Feature request - allow for content between open and close tag (2 posts)

  1. Ricki
    Posted 3 years ago #

    I am trying to create a shortcode that will display content only if no user is logged in.

    Example: [publiconly]No user is logged in. Display this[/publiconly]

    I would love to see GCB pick up the content between the tags as a variable called content that I can use in my php code.


  2. benz1
    Plugin Author

    Posted 3 years ago #

    Hi Ricki,

    I passed this onto my developer who replied as follows:

    Shortcodes can be embedded in content blocks, for example, if you have a shortcode definition like this:

    function caption_shortcode( $atts, $content = null ) {
       return '<span class="caption" style="color:red;">' . $content . '</span>';
    add_shortcode( 'caption', 'caption_shortcode' );

    it can be used directly in a post like this:
    [caption]this is a test[/caption]
    and will return
    <span class="caption" style="color:red;">this is a test</caption>

    You can also use it in a content block, like this:
    - create a new block (can be any type)
    - add something along these lines:
    this is a test block; here is a caption: [caption]this is a test[/caption]
    this will output, when run (either via do_shortcode or when viewed in page):
    this is a test block; here is a caption:<span class="caption" style="color:red;">this is a test</caption>

    So, both types of shortcodes are supported (enclosed or not).

    You have to remember that shortcodes do not execute other shortcodes that are in their content by default, so the fact that this plugin does is by design (check http://codex.wordpress.org/Shortcode_API).

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic


No tags yet.