A fresh mix of code snippets and tutorials

Enable shortcodes in widgets

Quick tip to enable WordPress shortcodes to be executed in widgets (and post content).

Enable WordPress shortcodes in widgets

Just add the following line to your theme’s functions.php file:

add_filter('widget_text', 'do_shortcode');

Enable WordPress shortcodes in post content

By default, shortcodes should be executed in WP Posts and Pages. If for whatever reason that is not happening, you can try adding the following snippet:

add_filter('the_content', 'do_shortcode', 10);

All together

Here are both of the previous snippets together, ready for quick grab, gulp, & go:

// execute shortcodes in widgets and content
add_filter('widget_text', 'do_shortcode', 10);
add_filter('the_content', 'do_shortcode', 10);

Nothing to configure, that’s all there is to it.

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress