One of the most frustrating things about widgets is that you cannot choose what pages to post them on. They are published to all pages, regardless. The only way to manage where your widget is seen is to use a plugin. The other problem is that you have limited options, so I will take you through a few and let you can decide which ones work for you.
Show or Hide Widgets with Jetpack
If you are using Jetpack, it has a module called Widget Visibility.
The Widget Visibility module enables you to configure widgets to appear only on certain pages (or be hidden on certain pages) by using the Visibility panel.
To enable this feature, go to Jetpack → Settings → Writing, scroll down to the Widgets section, and toggle the switch labeled Enable widget visibility controls to display widgets only on particular posts or pages.
When you open a widget, you should see the “Visibility” button.
Visibility is controlled by several attributes:
For example, if you wanted the Archives widget to only appear on category archives and error pages, choose “Show” from the first dropdown and then add two rules: “Page is 404 Error Page” and “Category is All Category Pages.”
Note: The red X is to remove the conditional.
You can also hide widgets based on the current page. For example, if you don’t want the Archives widget to appear on search results pages, choose “Hide” and “Page is Search Results.”
Using the Widget Logic Plugin
Let’s try out a plugin called Widget Logic to show or hide widgets.
I’ve used this in the past, but in my opinion, it’s not going to be easy for many WordPress users. For me, it was OK because I design WordPress themes and use conditional tags in my coding which determines what will happen based on certain conditions.
Widget Logic can be useful if you have an understanding of how they work in WordPress. You can control widget visibility by using WordPress Conditional Tags in a text field that is added to your widgets as “Widget Logic“.
Simple, yet the challenge is to know what conditional tag(s) to use. To give an example, let’s show this widget on a page that has an ID of 23:
Or, let’s hide our search widget from a full post that has an id of 65, but publish it on other pages:
Did you notice the ! exclamation mark right before the conditional? That means don’t show it on that post.
You can also add more conditionals in this text field with a varying array of combinations. But the more you add, the more confusing it might get.
Using the Widget Options Plugin
Widget Options is another plugin that offers more than what you really need, but I will keep this short.
I use this plugin for the Rough Pixels website and for several of the live demo sites for my themes. I don’t use all the features of this plugin, but let’s dig right in to what is relevant here.
When you first install this plugin, there are settings that you will need to contend with. Most of them you can keep disabled, but there are three sections that you may want to enable and configure.
It depends on how far you want to take the options to show or hide widgets, but the above boxes are settings I always enable. You can probably ignore the Hide Title one, but that simply adds a setting to your widget if you want to hide the widget title.
When you open a widget, you will see a group of tabbed settings:
You can even use conditional tags here too, but overall, there’s more to this plugin to make it almost comprehensive. More than Jetpack’s option and Widget Logic. After you use this for a while, you can find your way around the settings a lot easier.
The only complaint I have is that the developer for this plugin is very pushy with the admin area notices for you to rate it and/or upgrade to the premium.
One other item I should mention about this plugin is that it does have an export/import feature for your widgets. However, I would recommend reading through their documentation on using this plugin.
One Other Plugin – WP Toolbelt
A newer plugin to compete with Jetpack is called Toolbelt. I’ve been testing out and has a feature to manage where to publish widgets ( a suggestion made by yours truly ).
Ben has done a very good job with it and still continues to develop it. However, let’s get into the widget part of it and enable the module. You can find this setting under the main admin menu group; listed as “Toolbelt”. You will want to check the box next to the “Widget Display” option.
Once done, you can then see what gets added to your widget. You may notice it looks like the Widget Logic plugin, but he’s done something a bit different from how you enter in conditional tags. You can see more about this in his Github documentation with examples.
If I do a conditional based on this:
postCategory: 3 Display on single posts that are in category 3.
Then this widget will only show on all posts that exist in the category having an ID of 1.
WordPress is Changing – How About Widgets?
You may already know that WordPress and themes are changing, which all started with the Gutenberg Editor. However, many are not aware that widgets are being converted to “blocks“. I would say within a year, all widgets will be blocks, and once that happens, it will be interesting to see how we will show or hide widgets on select pages.
One more thing to consider as it relates to the future of WordPress, themes can also give you some widget management with templates. For Rough Pixels, we create themes with several sidebar positions where you can drop widgets into. When you make a page, you can select the page template of choice, and each one will have specific sidebars available. Still, having a dedicated method of publishing widgets to select pages do offer a much better experience—even when you change themes.
Showing or hiding widgets on select pages is a great way to help achieve different types of page layouts. It also helps prevent widgets being published on every single page or post of any given website. But having the ability to manage widgets makes things so much easier. You just need to decide which method we talked about will work best for your website.
If you’re already using Jetpack on your website, then the choice is already made for you. Simply enable the Widget Visibility option (module) in Jetpack, and then you are good to go! However, if you are not using Jetpack, then you have the other options to consider, but I would not recommend installing it just for widget management.
The best advice I can give you is to try each method and see what one you prefer.
If you have any other options and alternatives to what we talked about here, please post them in the comments.