WebCraft Tools

  • News
  • WordPress
    • WordPress Basics
    • WordPress Advanced
    • WordPress Performance
    • WordPress Security
    • WordPress Commerce
    • WordPress Troubleshooting
    • WordPress Themes
  • SEO and Analytics
WebCraft Tools › WordPress Advanced › Use shortcodes in the WordPress text widget

Use shortcodes in the WordPress text widget

Last updated on April 19, 2017 by Editorial Staff

Ever have this really cool shortcode that you wanted to use in your sidebar? You paste it in the text widget and save your changes but when you view your page you just end up with the shortcode itself?

The reason for this is simple. The WordPress text widget doesn’t parse shortcodes by default. So when you place your shortcode in the widget it just sees it as basic text. But there is a super easy way to remedy that. Just add the code below to a functionality plugin.

[php]

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

[/php]

The first line is only needed if you plan on having other text or elements and checking the “add paragraphs automatically” box. Otherwise WordPress might wrap your shortcode in paragraph tags and you don’t necessarily want that.

That’s all there is to it and I hope you enjoy.

Tweet
Pin
Share
0 Shares

Filed Under: WordPress Advanced

Leave a Reply Cancel reply

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

Site Links

  • Contact Us
  • Disclosure Statement
  • Privacy Policy

About WebCraft.tools

WebCraft.tools is your free resource for building, maintaining, and improving your WordPress website. Whether you are building your first site or have been building them for years, WebCraft.tools aims to provide you with tips, tricks, tutorials, and reviews to take your WordPress site to the next level.

© 2017 - 2021 · WebCraft Tools · Built by the WP Ninjas, LLC