Creating a sidebar on your website is an excellent way to display elements across all of your web pages. WordPress shortcodes can enable you to do this. However, if you’re new to the CMS, you might not know how to use shortcodes in sidebar widgets.
The good news is that the process ⚙️ is relatively straightforward. What’s more, you can choose from a few different approaches based on your site’s setup and your personal preference. For example, you can use the Site Editor or simply enable shortcode in all your widgets.
A brief introduction to WordPress shortcodes
First things first, if you’re new to WordPress, you might be wondering what shortcodes are. In a nutshell, WordPress shortcodes are small bits of code that are indicated by brackets, like
[this one]. They have been around since WordPress Version 2.5 .
Since WordPress Version 4.9, you can add these shortcodes pretty much anywhere on your site, including posts, pages, and custom post types. Shortcodes can perform tons of different functions and create lots of different design elements, like captions, galleries, and more.
Most versions of WordPress come with a lot of shortcodes built-in, but you can also use shortcode plugins to get even more. In the Block Editor, you can simply use the Shortcode block:
Or, you can add them manually in the Classic Editor.
However, if you want to use shortcodes in sidebar widgets, things aren’t as straightforward. Plus, how you do this will depend on both your theme and WordPress version. But don’t worry, we’ll show you three ways to do this later on in this post!
So, why use WordPress shortcodes in sidebar widgets? Before we answer this question, let’s quickly talk about widgets.
Essentially, WordPress widgets are modules that enable you to add unique and often interactive features to your site. You can include these widgets in different global widget areas, such as your sidebar, header, and footer.
That means you can add features that appear on every single page on your site in one fell swoop. For example, you can use widgets to add a search bar, a categories list, or a recent posts list:
Keep in mind, though, that you don’t have to create a sidebar for your entire site. You can also just feature one in all your blog posts or certain locations like the home page.
There are tons of free sidebar widgets to add dynamic elements like social media feeds, Google Maps, and events calendars. Then, when you add the power of shortcodes to your sidebar widget area, the possibilities become almost infinite!
How to use shortcodes in sidebar widgets
Now, we’re going to show you three ways to use shortcodes in sidebar widgets!
- Using the Site Editor
- With the WordPress Shortcode widget
- Using custom code to enable shortcodes in widget titles
1. Using the Site Editor (block themes only)
If you’re using a block theme such as Raft, Neve FSE, or Twenty Twenty-Two, then you’ll be able to use the WordPress Full Site Editor (FSE). This enables you to modify site-wide elements (like a sidebar) using blocks. Since there is a Shortcode block, this process is super simple.
To get started, go to Appearance > Themes > Editor. This will launch your Site Editor, where you can access your menus for Templates and Template Parts:
Select the template or part where you want to add the sidebar.
Choose a variation for your sidebar. We’ll select the 66/33 option for a right sidebar.
Then, to move any content to the left side, open your List View:
Drag the main content to the column on the left. This will leave your right sidebar empty:
Finally, search for your shortcode block and add it to your new sidebar:
Then, add any unique shortcodes that you like and click on Save when you’re done.
Just remember, once you finalize this design, it will be implemented on all pre-existing and future posts that use the template.
2. With the WordPress Shortcode widget
If you haven’t made the switch to block themes and the Site Editor, you can use the WordPress Shortcode widget in your block-based widget editor.
To do this, simply go to Appearance > Widgets:
Then, if your active theme already has a sidebar, select it. Click on the plus (+) symbol and search for the Shortcode block widget:
After that, you can write in any shortcode that you want:
It’s as simple as that!
However, keep in mind that you can also disable block-based widgets to use classic widgets if that’s your preference.
3. Using custom code to enable shortcodes in widget titles
If you’re interested in getting a more specialized functionality and have shortcodes work not only in the body of the widgets but also the titles, then you’ll need to set up a custom solution for that. It’s still pretty easy to do, though!
Start by making a backup of your site (just in case anything goes wrong).
Then, install the Code Snippets plugin, and create a new PHP snippet. Put this code in the body of the snippet:
Set the new snippet to work on the frontend of the site:
Save the new snippet.
This will enable shortcodes not only in the widgets but also their titles! 💪
If you want certain design features to appear on all of your web pages, utilizing your sidebar is a fantastic strategy. However, if you don’t have any web design skills, you may not know how to do this.
Fortunately, with WordPress, you can use shortcodes in sidebar widgets in order to create tons of unique elements like social media feeds, sign up forms, and more. Plus, there are a few ways you can use these shortcodes. With a block theme, simply use the Full Site Editor. Otherwise, try the WordPress Shortcode widget or simply enable shortcodes 🔧 in all widgets.
Do you have any questions about how to use shortcodes in sidebar widgets? Let us know in the comments section below!