I have one shortcode that should be always next to the sidebar:

// [shortcode] otuput | default sidebar 

My theme allows me to set different sidebars for each page. So I have sidebars on a few pages, but not everywhere.

What's the best/proper way of achieving this goal? I was thinking about adding dynamic_sidebar($sidebar_name) to the shortcode itself, but it doesn't seem to be smart idea (especially with multiple instances of my shortcode at the same page).

  • 1
    What is the shortcode doing? I'm unclear on where that's being output - have you put the shortcode in page/post content or is it being rendered via a template?
    – Michelle
    Jul 30, 2011 at 19:12
  • The shortcode uses WP_Query to loop items from given post type. Jul 30, 2011 at 19:30

1 Answer 1


I'm still not sure exactly what you're trying to do, but here's one possibility if it's to display something like this:


Do you have control of the shortcode content? If so, you could update it so its output is wrapped in a <div id="shortcodecontent"> --shortcode post-loop output-- </div>.

Then add a text widget to your sidebar and insert the [shortcode] within it. If shortcodes aren't rendering when inserted in widgets, add the following line to the functions.php file within your theme:

add_filter('widget_text', 'do_shortcode');

Now, the shortcode output will appear first, before any of the other widgets in your sidebar. Using CSS, style the wrapping #shortcodecontent div so that your shortcode widget floats to the left of the other widgets in your sidebar.

Hope this helps in some way! Best of luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.