If you own a WordPress site, have you ever have the need to display different widgets for different pages? For example, you might be running a travel site and you blog about travelling in various countries. You might want to get the sidebar to display a France’s hotel booking form when the content is about France or the recommended Italian restaurant widget when you are discussing about Italy. How do you achieve that in WordPress? How do you achieve that in WordPress without having to meddle with the code?
1. Conditional Widgets
As its name implies, Conditional Widgets is a plugin that allows you to define a conditional rule for each and every widget.
After you have downloaded and activated it, go to your Widgets page and add the widgets you want as per normal. What is different now is that within each widget, there is an option for you to configure when the widget should appear in the blog (refer to the screenshot below).
You can get it to show/hide on the Home page, certain categories, or even certain pages. It also supports sub-categories and sub-pages. You just need to define the rule for the parent category/page and their sub-categories and sub-pages will follow suit.
One thing though, it does not allow you to configure on a per-post basis.
2. Widget Logic
Widget Logic is less intuitive than Conditional Widget, but it gives you the flexibility to define where the widget should appear. Widget Logic make use of the WordPress conditional tags to determine where the widget should appear. For example, if you want the widget to appear on a post with post id 46, you place the conditional tag
is_single(46) in the Widget Logic field.
3. Section Widgets
The way that Section Widgets works is slightly different from the above two, but it is also the most powerful among the three. Other than the conditional logic, Section Widgets also allows you to create a tabbed sidebar without having to write a single code.
After the installation, go to “Themes -> Section Widget“. This is where you can customize the look and feel of the tabbed interface. It comes with 25 UI themes for you to choose. If none of them caught your eyes, you can even define your own style.
In the Widget section, instead of adding a conditional logic to each and every widget, you will have to add the “Section” widget to the respective sidebar in order for it to appear. Each Section widget comes with two part. The upper part is where you define the condition (which page/category to appear) and the lower part is the HTML code to display.
To add a tabbed widget, drag and drop the “Section (tabbed)” widget to the respective sidebar. Similarly, the top section is where you define the logic and the bottom is where you create tabs and add content to it.
While Section Widget is very powerful, it does have one caveat – it doesn’t integrate with other widgets. If you have a custom widget (say the custom menu) that you want to show conditionally on your blog, you won’t be able to do that with Section Widget.
Which method do you use to add conditional widgets to your WordPress site?
Our latest tutorials delivered straight to your inbox