How to Use Shortcodes in WordPress Widgets

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 allows you to run shortcodes in many different places. You can use shortcodes in the text area of Posts and Pages. You can use shortcodes in WordPress emails.

However, by default, WordPress doesn’t execute shortcodes inside the default text widget. This tutorial will show you an easy way to get shortcodes working in widgets.

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’);

Author

  • Nick Savov

    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.

0 0 votes
Article Rating
Subscribe
Notify of
2 Comments
Oldest
Newest
Inline Feedbacks
View all comments
wpdeveloper
wpdeveloper
3 years ago

Excellent post! Thanks for the content.It saves my time. Thanks a lot.

mikall
3 years ago
Reply to  wpdeveloper

so glad you found OSTraining! And happy to help.  Thanks for posting!

2
0
Would love your thoughts, please comment.x
()
x