WordPress.org

Ready to get started?Download WordPress

Forums

Global Content Blocks
[resolved] Shortcode in block seems to not work (5 posts)

  1. dfumagalli
    Member
    Posted 2 years ago #

    Hello,

    I have created a simple block as follows:

    <div>
    <div style="float: right;">%%div_contents%%</div>
    </div>

    I had to use the editor in HTML mode else it'd "interpret" the div and would also add extraneous nbs and <p>.

    Later on, I type this in the editor:

    [contentblock id=1 div_contents="[slideshow]"]

    Upon saving the post or switching between HTML and Visual, I get a broken content block image that is missing the last two characters: "] and the same two characters appear next to the right of the content block image.
    Saving and viewing the page shows the whole content block doing nothing and all you see are those "] character.

    I don't know if this has anything to do with this WP shortcode API notice:

    http://codex.wordpress.org/Shortcode_API

    The shortcode parser does not accept square brackets within attributes. Thus the following will fail:

    [tag attribute="[Some value]"]

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

  2. benz1
    Member
    Plugin Author

    Posted 2 years ago #

    Hi dfumagalli and apologies for the delay in responding.

    I past this onto my developer who responded as follows:

    You cannot use square brackets inside the block parameters, like that.
    What I suggest is using something along these lines:

    The block code could be:

    <div>
    <div style="float: right;">
    
    [%%div_contents%%]
    
    </div>
    </div>

    and then, for the parameter, he could use:

    [contentblock id=1 div_contents="slideshow"]

    That would produce :

    <div>
    <div style="float: right;">
    
    [slideshow]
    
    </div>
    </div>

    in the end, so that would be good.

    The problem with the above might be that he wants to set more than a shortcode inside that div. In that case, he could use multiple parameters, or multiple content blocks, or even use the ability to embed blocks into others.

    Hope this helps.

    Regards,
    Benz1

  3. dfumagalli
    Member
    Posted 2 years ago #

    @Benz1

    Thank you for your reply, you are most kind!

    Your fix indeed works but I needed a more general block able to digest both regular code and short codes. It'd become a content aligmnent template I used for a whole section of my website regardless of the parameter contents. That's why I'd pass the whole square brackets.
    I hoped to find a way to "escape" the brackets so the WordPress shortcode parser would not get confused.

    Anyway, in the end I have done a solution like yours. It's less general but it gets the job done.

    Best regards,
    dfumagalli

  4. benz1
    Member
    Plugin Author

    Posted 2 years ago #

    Glad you managedto get it working.

  5. dfumagalli
    Member
    Posted 2 years ago #

    Glad to see such a caring Developer :D
    Keep the good work.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic