WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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).

share|improve this question
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 '11 at 19:12
The shortcode uses WP_Query to loop items from given post type. – Wordpressor Jul 30 '11 at 19:30
up vote 0 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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