WordPress Quick Tip: How To Use Shortcodes in Widgets

  • follow us in feedly
Published August 4, 2013 by Brad Knutson
WordPress Quick Tip: Use Shortcodes in Widgets

If you’ve read a handful of my blog posts, you’ve probably noticed that I like to use WordPress shortcodes. Whenever I am faced with a problem, the first place I look to solve it is with a custom shortcode.

Recently, I came across a situation where I needed to use a shortcode in a sidebar widget area. If you are a WordPress developer, you know that by default shortcodes don’t work in widgets. This has to do with the order that WordPress processes the PHP scripts on the server.

The good news is that it is possible to use shortcodes in WordPress widgets. In fact, it’s really easy. All you have to do is add one line of code to your theme’s functions.php file.

<?php add_filter('widget_text', 'do_shortcode') ?>

That’s it, now shortcodes will function normally when used in widgets.

The following two tabs change content below.
Founder at Inbounderish
Brad Knutson is a Web Developer in the Twin Cities area of Minnesota. He has experience working with WordPress and Drupal, and also has an interest in SEO and Inbound Marketing.

Keep Up-to-Date

Subscribe

Topics

See a complete list of topics discussed in blog posts here.

Check These Out

Get 2 Weeks Free! Sign Up Today! Premium Managed WordPress Hosting Genesis Framework for WordPress SEO is complex. Tools should be simple. Thesis Theme for WordPress:  Options Galore and a Helpful Support Community

Share Your Thoughts

Your email address will not be shown.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">