Widget Shortcode
29 May, 2013 — Snippets, WordPress

Use Shortcodes Within The WordPress Text Widget

For some reason I have yet to think of by default, WordPress shortcodes do not work within text widgets. Why I have no idea but if you need this functionality, it is quite easy to accomplish, simply follow the steps below.

  1. Log into your WordPress Dashboard
  2. Under “Appearance” click “Editor” (if you cant see this it might be disabled – if so contact the company who created your theme)
  3. In the list of files on the right of the page, click “functions.php”
  4. At the bottom of the functions.php file, add the following code:

add_filter( ‘widget_text’, ‘shortcode_unautop’); add_filter( ‘widget_text’, ‘do_shortcode’);

Click “Update File” and as if by magic your shortcodes should now work in your text widgets!

Although this way does work it might not be the best way of doing thing if your theme is regally updated or there is a chance your theme could be changed. If you use a theme from the third party that does get updates you might want to consider making yourself a simple functionality plugin.