Keep WordPress widgets from appearing on particular pages

28 April 2010 · 9 comments

This WordPress plugin makes it comparatively easy to customise which widgets appear on which pages.

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.

[Via Freaky Trigger's WordPress Setup | FreakyTrigger.]

Widget Logic.

Widget Logic.

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

  1. Install and activate Widget Logic.
  2. Find the ID for the Post (see below).
  3. Open the widget you wish to hide.
  4. Add the correct PHP instructions (see below) in the Widget Logic text box below the widget.
  5. Save the widget.
  6. Test.

Find the ID for a Post

Find the ID of a Post.

Find the ID of 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: http://knowit.co.nz/wp-admin/post.php?action=edit&post=4133.

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 4133.

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.

is_single('4133')

is_single(’4133′)

The PHP code that expresses that requirement is:

!is_single('4133') 

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.

9 comments

Older Post:

Newer Post: