Title: Shortcode in widget curiosity
Last modified: September 1, 2016

---

# Shortcode in widget curiosity

 *  Resolved [msummers](https://wordpress.org/support/users/msummers/)
 * (@msummers)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/shortcode-in-widget-curiosity/)
 * 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)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [9 years, 10 months ago](https://wordpress.org/support/topic/shortcode-in-widget-curiosity/#post-7659543)
 * 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](https://wordpress.org/support/users/msummers/)
 * (@msummers)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/shortcode-in-widget-curiosity/#post-7659602)
 * Zounds! What an important thing to know. Thank you so much, Steve. It works fine
   now.
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [9 years, 10 months ago](https://wordpress.org/support/topic/shortcode-in-widget-curiosity/#post-7659604)
 * Gadzooks!

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

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/shortcode-in-widget-curiosity/#post-7659604)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
