Keep WordPress widgets from appearing on particular pages

28 April 2010 · 6 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.

6 comments

Need help with WordPress?
I set up WordPress-based websites, provide training and support. Contact me for more information.

The Thesis Theme for WordPress (affiliate link) saves me heaps of time. Buy it and find out for yourself.
Thesis Theme for WordPress:  Options Galore and a Helpful Support Community.

These Posts may interest you too:

  1. WordPress and Widgets The Peachpit: Web Design Reference Guide has published the latest in my series of WordPress articles: Customizing WordPress: Using Widgets: Before widgets, changing the sidebar on your blog meant rummaging...
  2. WordPress Instructions for clients A handy plugin lets web developers leave instructions for clients right inside the WordPress Dashboard. ...
  3. Widgets for web developers Lisa McMillan describes cool widgets for web developers: Bestof. Dashboard for web developers edition. Includes widgets for the total number of hits to your site, CSS Cheat Sheet, colour selector,...
  4. Make the most of WordPress Pages My most recent article in the series at Peachpit Web Design Reference Guide has appeared — Customizing WordPress: Make the Most of Pages: Posts are the lifeblood of any blog,...
  5. How to use those darn Widgets My Mac Tip #213/21-September-2005 is More on Widgets … Type the name of your town or city (or one nearby) and press the Return key (that’s the trick). After a...

Tell us what you think.
Note: there may be a delay before your comment appears. I now approve all comments from new visitors, in an attempt to keep spam at bay.

{ 5 comments… read them below or add one }

Chris Beaman 18 May 2010 at 10:29 58

This was very helpful. I’ve been using Widget context, which is cool, but I wanted more customization across the board.

Reply

Miraz 18 May 2010 at 12:03 49

I’m glad this info helped, Chris.

Reply

Doug C. 22 July 2010 at 03:26 07

Just an FYI: Widget Logic does not work with WP version 3.0 (at least it doesn’t for me). I’ve found various comments around the Web (including the Widget Logic WP support page) from other users who claim it is not working for them on WP version 3.0, either.

Reply

Miraz 06 August 2010 at 14:50 20

Hi Doug, this blog’s using WordPress 3.0.1 and the plugin is doing its job for me. It removes the BlogHer ad from top of the left sidebar on this page:

http://knowit.co.nz/2010/04/enjoy-quick-efficient-and-timely-tech-training

Reply

Kate 30 August 2010 at 06:10 16

I was having problems (like others) with getting Widget Context to eliminate occurrences of particular widgets on particular pages. I discovered, though, that if you select the box on the left that says “Single Page” and then list the pages on the right (I used no slashes on either side) on separate lines, it works like a dream.

Reply

Add your Comment

{ 1 trackback }

Previous post:

Next post: