How To Use Shortcodes in WordPress Widgets

How To Use Shortcodes in WordPress Widgets featured image

Shortcodes are great, and can be used for a variety of purposes within WordPress to cut out the hassle of adding code all over the place.

Even better, shortcodes allow you to edit things centrally and have them updated wherever they appear across your blog.

But, often, we find, our clients would like a feature in a sidebar, header, or footer widget which would be best driven by a shortcode.

WordPress doesn’t let you put shortcodes into widgets out of the box. But, with one simple modification, you can get this working on your WordPress website!

How to Do It

The fix is as follows:

  1. login to WordPress
  2. Under Appearence > Editor, visit the functions.php page of your current active theme
  3. Add the following code to the bottom of that file:

add_filter('widget_text', 'do_shortcode');

Where to put this code

NOTE: This should be added before the closing ?>

Next, hit “Update” and then add a text widget with a shortcode in it to see how this performs.

NOTE – use a child theme

When making edits of this nature to functions.php, you should do so in a child theme. If you do not have a child theme, then add this to a custom functions plugin. Do not edit your theme – it will be copied over next time you update your theme… and you must update your theme when new versions are ready.

Leave a comment with questions or issues

Any problems, leave a comment below for us to solve publicly, and help out the community of people who also face the same issue!

Get Silicon Dales to help

If you can’t manage the above work, feel free to contact us about having Silicon Dales manage your WordPress website on your behalf.

Leave a Reply

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