WordPress: Shortcode in Text Widget

By default, WordPress doesn’t parse WordPress or other 3rd party shortcodes in text widgets. I often see people putting shortcodes into text widgets and wonder why nothing is displayed.

To parse and output shortcodes in text widgets, you need to modify your WordPress theme and put the following code into the “functions.php” file of the theme.

<?php add_filter('widget_text', 'do_shortcode'); ?>

You’re simply hooking onto the widget_text filter hook of WordPress which passes and returns the content through the function you specify. In this case you’re sending the widget_text content to do_shortcode() which is a WordPress core function that parses shortcodes in a string/content.

And that’s it, you can now put shortcodes into WordPress text widgets.


  1. Adrian on May 4, 2012

    Hi Antonie, thanks for looking into this issue, it is a great help to be able to put the MaxButtons shortcode (and any shortcode for that matter) into the sidebar area. Quick question, does it matter where I put the code into the functions.php theme file? Where would be a good place to put it? Thanks!

  2. Al on June 12, 2012

    Hi Thanks for bringing this up. Could you also help with doing it the other way around? I want to add widgets in my pages as short codes. Is that even possible?


Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

%d bloggers like this: