I found I needed a way to remove a sidebar widget from only one Post. I figured there was probably a WordPress plugin that could help. It took only a few moments searching to find this:
Widget Logic allows widgets to appear or not depending on standard WP conditional tags, such as is_home() and is_single() and so on.
It was quick and easy to install, but then I was a bit stumped about exactly how to use it. If you’re in the same boat, here’s what to do.
How to hide a sidebar widget for a single Post
- Install and activate Widget Logic.
- Find the ID for the Post (see below).
- Open the widget you wish to hide.
- Add the correct PHP instructions (see below) in the Widget Logic text box below the widget.
- Save the widget.
Find the ID for a Post
To find the ID for a Post go to the
Edit Posts section of the Admin area.
Locate the correct Post and hover over its Title in the list of Posts.
As you hover over the Post title look in the Status Bar of your browser. You should see something a bit like this:
The first part of what you see doesn’t matter; look for the numerals at the end, after
post=. The Post I wanted to work with had the ID of
Another way to do this is to Command Click (Right Click) on the title of the Post and Copy the URL. Then paste the URL in your text editor to see the ID number.
Add the PHP
Although there were some instructions at the Widget Logic plugin page, I still wasn’t quite sure what I needed to enter into the widget’s new text field. Here’s what I needed to do.
I wanted to have the widget be visible all over my blog, except on the one single-page for the Post whose ID was 4133. I did want the widget to be visible on the Home Page, my About Page, pages where other Posts appeared on their own.
The PHP code that expresses that requirement is:
In English that says: is not (!) the single Post page (is_single(”) ) whose ID is 4133.
The implication is that if it’s not that specific page then go ahead and display the widget.
In fact that was all I had to enter into the Widget Logic text area below the widget. I didn’t need any opening stuff or ‘if’, or semicolons to finish it off.
If you need to stop specific widgets appearing on particular pages then give Widget Logic a try.