Shortcodes are WordPress-specific codes which allow some plugins to easily embed content into your posts or pages.

Cloudways

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 add the generated shortcode inside whatever page you want. That’s it!

Cloudways

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!

Click here if you want to jump to the video tutorial.

Cloudways

Enable shortcodes for your widgets

First, you need to access your theme’s functions.php file. You can do that using 3 methods.

I strongly recommend having a child theme in place, otherwise, the changes will disappear with the next update!

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:

wordpress theme editor

Cloudways

2. Find Theme Functions (functions.php) on the right and click on it.

3. Now add this code at the very bottom: add_filter('widget_text', 'do_shortcode');.

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' );

enable shortcodes in WordPress widgets

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:

cpanel file manager

2. Under public_html, go to /wp-content/themes/yourtheme-child/ (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.

editing functions.php through cpanel

3. Go at the very bottom of the file and the code: add_filter('widget_text', 'do_shortcode');.

enable shortcodes in wordpress widgets

4. Press Save Changes and you’re done!

Method 3 – Using an FTP client

You could use a 3rd party software like SmartFTP or FileZilla.

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:
wordpress 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:
twitch widget shortcode

4. Click Save and check things out.

Note that some plugins, like Contact Form 7, work inside the widget area without the code in functions.php, so make sure you give it a try before adding that line of code.

Video Tutorial

You might want to read:

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!