Shortcodes are WordPress-specific codes which allow some plugins to easily embed content into your posts or pages.
Here’s an example of a shortcode used by the Contact Form 7 plugin:
[contact-form-7 id="2020" title="Contact"]. After you create your contact form inside the plugin and save it, you just paste the generated shortcode inside whatever page you want. That’s it!
The bad news is that shortcodes don’t normally work on widgets, they only work on posts and pages. The good news is that there’s a way to enable them!
We recently configured a site for one of our clients, and he wanted some Twitch streams added in his sidebar. Thanks to the awesome workaround we’re going to show you, he now has them!
Enable shortcodes for your widgets
First, you need to access your theme’s functions.php file. You can do that using 3 methods.
Method 1 – Using your theme editor
1. If you’re not blocking this feature from within your security plugin, you’ll find the theme editor by going to Appearance -> Editor:
2. Find Theme Functions (functions.php) on the right and click on it.
3. Now add this code at the very bottom:
Update: Add an extra line of code just above the first one, so the code should have two lines now and be like this (in the exact order):
add_filter( 'widget_text', 'shortcode_unautop' );
add_filter( 'widget_text', 'do_shortcode' );
4. Press Update File and you’re done!
Method 2 – Using your hosting control panel
For this example, we’ll use cPanel.
1. Log in to your cPanel and find File Manager:
2. Under public_html, go to
/wp-content/themes/yourtheme/ (you need to select whatever theme you’re using; we’ve selected twentythirteen for the sake of the example). Now, find the functions.php file, right-click on it, and select Edit or Code Edit. A pop-up may appear – just press the Edit button on it.
3. Go at the very bottom of the file and the code:
4. Press Save Changes and you’re done!
Method 3 – Using a FTP client
The file editing process is like the one explained at the second method. You only need to connect your FTP client to your server. Here are tutorials on how to do that (it’s easy):
Use a shortcode in a widget
1. In order to add a shortcode in a widget, you need to go to Appearance -> Widgets:
2. Drag a Text widget to your sidebar.
3. Add a title to the widget, if you wish, and then insert the shortcode generated by the plugin you want to use. In this example, I’ll add a Twitch TV Embed Suite plugin shortcode:
4. Click Save and check things out.
That’s a wrap
Hope you enjoyed our guide and found it useful!
If you have any questions, or just want to share your thoughts with us, please leave a comment!