How to Use Shortcodes in WordPress Widgets

| WordPress
How to Use Shortcodes in WordPress Widgets

One of our OSTraining members was having an issue with shortcodes in widgets, so we created a tutorial for her.

By default, WordPress doesn't execute shortcodes inside the default text widget. This tutorial will show you an easy way to get shortcodes working.

The image belows show the problem we face. We put a shortcode into a widget, but it shows up as plain text.

WordPress widgets show shortcodes as plain text

Let's install a plugin to fix this.

  • Install and enable the Shortcode Widget plugin
  • Go to Appearance > Widgets.
  • You'll now see a new widget type called "Shortcode Widget".
A new Shortcode Widget type
  • Add the Shortcode Widget to your sidebar:
Adding Shortcode Widget to your sidebar
  • On the right side, you can now add your [shortcode] to your Shortcode Widget's content:
Adding a shortcode to the Shortcode Widget
  • Check your front-end and the shortcode will now. That's all there is to it. Enjoy!

Shortcode Pro Tip

You can execute shortcodes in the regular WordPress text widget by adding the following code to your functions.php file of your child theme:

add_filter('widget_text', 'do_shortcode');


About the author

Nick is the Director of Support at OSTraining and you can find him in almost every area of the site, from answering support requests and account questions to creating tutorials and software.