Do you want to insert shortcodes in text widgets? Well, another super useful WordPress tip is coming your way. It’s also quick and painless.
NOTE: For the uninitiated, shortcodes are essentially instructions written inside [square brackets]. Depending on how awesome your theme is or the plugins you’ve installed you may have the ability to use some custom shortcodes to create certain types of content in your pages or posts.
By default, WordPress filters the ability to perform these types of custom actions inside text widgets. So let’s unlock this ability now! Simply…
Follow these 5 quick steps to allow shortcodes in widgets.
1. Log into your WordPress site.
2. Navigate to Appearance>Editor
3. Select your Theme Functions file.
4. Make a back up! Before inserting the following piece of text in step 5, please make sure you have a recent backup of this file as one tiny mistake could spoil your day. Gain access to your site’s file structure via FTP or your host’s control panel and copy/save the existing functions.php file from your active theme to your computer. Upload this file immediately if the next step fails.
5. Paste the following piece of text into the bottom of your Theme Functions file.
// Enable shortcodes in text widgets add_filter( 'widget_text', 'shortcode_unautop'); add_filter( 'widget_text', 'do_shortcode');
…and that’s it. 🏆
You have just enabled the use of shortcode instructions in text widgets. Now, go forth and create wonderful websites.
The function deconstructed
The first line of the three is just a comment. It’s main function is to tell you what the following lines of code are doing.
The second line of the three critically removes the auto paragraphing function that can disrupt how shortcodes work. (Not always mentioned on other posts you may have read – but useful to have just in case)
The third line is doing all the hard work. It’s saying…
Hey WordPress, when you start creating text widgets on my site, enable shortcodes will ya?
OK, that was weird! Ahem…
If you found this post useful please consider sharing it.
The Zaposphere Team