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.

  • http://www.e3corporate.com Adrian

    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!

  • http://mrjeevescrm.com Al

    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?