There are a number of WordPress theme plugins that give you a shortcode to add the plugin content to a WordPress post or page, but they have no widget to use in a widget area. But what if you want to add the plugin content to your WordPress sidebar or a widget area in your home page?
If we could use shortcodes, it would be especially useful for themes that have extra widget areas on the home page, including the Twenty Twelve theme and many Genesis child themes. Some plugin examples with shortcodes, but without widgets, include sliders, testimonials, contact forms, videos, advertising, and galleries. This tutorial will show you how you can add content by using these shortcodes in your WordPress website sidebar widget areas.
Add Filter Code to Theme Functions
Step 1. You need to add one line of code to your functions.php. You can also install a plugin, like Code Snippets, to add the line of code as a Snippet. Add this line of code (and the comment) at the end of your child theme’s functions.php and save. If you use Code Snippets, be sure to activate the code snippet after saving.
/* Allow shortcodes in widget areas */ add_filter('widget_text', 'do_shortcode');
Step 2. Next find the widget area you want to use. In your WordPress Dashboard, go to Appearance > Widgets.
Step 3. Add a Text Widget to your widget area, maybe your Sidebar. Yes, you’re going to add the shortcode to a Text Widget.
Step 4. Then add the shortcode and save.
Let’s look at some examples.
Add a Slider to a Sidebar
Soliloquy Lite is a beautiful and easy to use slider. Once you create the slider, over on the right side, there will be a shortcode for you to use. The slider shortcode looks like this:
Copy and paste this code into your Text Widget, save, and you will have a slider in your sidebar.
Add a YouTube Video to a Widget Area
If you have the Jetpack plugin installed, it allows you to embed media – YouTube, Vimeo, Audio, etc. Using an embed shortcode you can add the media to your sidebar.
Find the YouTube video you want to uadd, and click on Share. You will get the URL. You may also need to change the size of the video to fit in your sidebar, so click on Embed. Then enter a size that fits your sidebar in the first (width) box. The height number will adjust. Then use the URL and the width and height numbers to create the shortcode embed code.
Add the YouTube shortcode to a Text Widget.
Add an Image Gallery to any Widget Area
You can also add a gallery to any widget. Maybe your small business website features new products. It’s easy to add a gallery. First create a gallery in any post. You can save it as a draft, if you don’t need it for your blog. Then in your editor box, click on the Text tab. This example uses thumbnails and two columns which fits nicely in a sidebar. Copy the shortcode and paste it into your sidebar Text Widget.
And this is how the shortcodes will look. This is a Genesis child theme home page, but the look will be similar in your sidebar widget areas.
So the next time you see a shortcode, think about adding it to your WordPress sidebar widget area. Please let me know if you have any other examples.