WordPress: Conditional Widget Display on Sidebar
Before when WordPress themes do not support widgets, we used to control lists on our sidebars via PHP modifications. It’s not a task for everyone, and widgets were created.
But the thing is, once you add a widget to your sidebar, it will automatically display itself on your homepage and your single pages as well.
Today I learned that you can control it, not via PHP, but on your style.css.
Every widget on your sidebar has a unique id. So you can control them easily on your style.css.
Ex.
li#tag_cloud { display:none; }
This will hide the Tags widget from the sidebar, but the thing is it won’t be shown to any page either. So you need to know what division it is included to. In my case, I use #home class for my main division when on homepage and #page class when on single pages.
So on my style.css, I have:
#page li#tag_cloud { display:none; }
This hides the Tags widget when on single pages.
You just have to make sure that you use different divisions for home and single pages. But if you have a better workaround for displaying widgets conditionally, let me know. I’d like to learn from you too.
[...] Read more… [...]