• Resolved msummers

    (@msummers)


    I have defined a shortcode that will be used in a widget to add a pseudo-server-side include to that widget, and have enabled the shortcodes in widgets option in the functions file. When I do that, the translated shortcode always appears ABOVE the section containing the widget contents . For example, if my shortcode is [shortcode], and I place an ordinary text widget in the primary sidebar area with the content –

    Contents contents Contents contents Contents contents Contents contents Contents contents.
    [shortcode]

    then the shortcode’s code appears ABOVE the <section id=”text-##” class=”widget widget_text”> even though it is actually physically below that widget’s content!

    Any ideas why that is, and ways that I can stop it?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    My bet is that you’re echoing content from the shortcode. Shortcodes are supposed to return a string. If any content is echoed, it will appear at the top and the actual shortcode return will appear wherever you put the shortcode.

    The easy way around this is to use ob_start() at the top of your shortcode and return ob_get_cl;ean() at the end — or you can just stuff everything into a string and return the string.

    Thread Starter msummers

    (@msummers)

    Zounds! What an important thing to know. Thank you so much, Steve. It works fine now.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Gadzooks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Shortcode in widget curiosity’ is closed to new replies.