Recently, I came across a problem I needed to solve on a client’s wordpress blog. How do I get different content to appear in the sidebar against different pages or posts?

Let me explain further.

I have a page which details a weekend training course. On the main home page, I have an advert for the course as a clickable image in the sidebar.  When a visitor clicks to read the course page, it is no longer relevant to have the advert for the course in the sidebar, but currently, wordpress content widgets are set to appear on all sidebars.

There is another option – I could use the ‘no sidebar’ page template, but I don’t like that either. I still want the majority of my sidebar content to display.

After posing the question on Twitter, one of my followers suggested a plugin called Widget Logic.

I will comment here that once I found the plugin (search for widget logic) and installed it, it took a bit of getting used to.  You MUST visit the plugin page on wordpress.org to understand how to use it & in particular the page that describes the way conditional tags work.

For example, use:

is_single()
For a specific widget to appear on ANY blog post

is_page()
For a specific widget to appear on ANY page

is_category()
For a specific widget to appear on ANY Category Archive Page

There are then variations to these & many more conditional tags that can be used for individual posts, pages, categories & page templates etc.

I was a little disappointed as I couldn’t get widget logic to just exclude specific sidebar content from a single page or post etc.  It only seems to work by instructing the widget to display the content.

So to solve my original problem, I had to use page ID’s & instruct the widget for the course advert to appear on a number of page ID’s leaving out the course page. This actually wasn’t as hard to do as it sounds, it would just be a little long winded if your blog has hundreds of pages.

If anyone manages to find a way to ‘exclude’ just one page, please let me know by adding a comment below