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.

Clip to Evernote

9 comments

Need help with WordPress?
I provide training and support for users of WordPress-based websites. 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.

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.

{ 8 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

andriansah 29 September 2010 at 20:17 29

Hi Miraz

Could you help me please.
On single page I want to extend the page from left to right, because I remove the sidebar with withd logic, could you tell me which file I have to edit and add so I can make it from left to right

Thanks

Reply

Miraz 01 October 2010 at 19:22 29

Andriansah: how you remove the sidebar and extend the main content to the full width of the page depends on which theme you’re using and how it deals with the sidebar.

In the Thesis theme that I use and recommend you simply choose a No Sidebars template for your page.

Reply

Craig 07 October 2010 at 23:13 17

Is there a way to stop a widget appearing on the homepage, but let it appear on all other posts/pages?

Reply

Add your Comment

Older Post:

Newer Post: