Nanny Goats in Panties Rotating Header Image

WordPress: How To Remove the Sidebar for Specific Pages

There are times when you want to remove or disable your sidebar for a specific page or post in WordPress. Maybe you host a giveaway or a product review and one of your Ad Networks won’t allow your post to appear on the same page as their ad.

This article describes several methods to disable a sidebar for an individual page or post:

  1. Method 1: Use a WP theme that has a simple “No Sidebar” option in the main WP Editor.
  2. Method 2: Disable sidebar using a custom field.
  3. Method 3: Disable sidebar for one page by modifying one of the php files (e.g., page.php)
  4. Method 4: Go nuts and disable sidebar for ALL pages by modifying one of the php files (e.g., page.php)

Method 1: Use a WordPress theme that allows easy selection of templates

I was using the Swift theme (and method 2 below) until its last upgrade in June 2010 and my “disable sidebar” method stopped working. So I simply switched to using PrimePress which lets you pick and choose which template you want to use for each page or post. See?

wordpress nosidebar template option

Under Page Attributes on the right-hand side, you’ll see a pull down menu under Template. Select “No Sidebars” and save your page or post. That’s it, you’re done.

You can download the theme from the PrimePress site or WordPress.org site. Or, even easier, try searching for it from your WP editor: Under Appearance, select Themes. Click on the Install Themes tab, and enter Primepress in the search box.  From there you can either install or preview the theme.

Method 2: Use a custom field to disable sidebar for a specific page

Note: This worked when I was using the Swift Theme (prior to June 2010 until it upgraded) and WordPress 3.0. Then I upgraded to a new version of Swift and this method stopped working.

The idea here is that you will modify your page.php file to check for a “disable sidebar” indicator (aka a custom field) for each page. Then, anytime you want to create a page with no sidebar, you simply set a custom field to indicate that you wish to disable the sidebar for that specific page. Ready? Here we go.

Modify your page.php file

In your WordPress Editor, go to Appearance / Editor and click on page.php. Scroll down to the bottom where you will see the line of code that displays your sidebar:

<?php get_sidebar(); ?>

Replace that one line with this:

<?php // if page has custom field called disableSidebar = true, remove sidebar
$disableSidebar = get_post_meta($post->ID, ‘disableSidebar’, $single = true);
if ($disableSidebar !== ‘true’) { get_sidebar(); }
?>

Save the file.

Add the custom field to your page

In your WordPress editor, go to Pages / Edit and select the page on which you wish to disable the sidebar.

Go down to the Custom Field area and add a custom field called disableSidebar. Set the value to “true“.  See example below.

disable sidebar custom field in WordPress

Save the page. You’re done.

Warnings and Tips

This method simply removes  the sidebar, it does not readjust the width of the content to fill all the way across the page. That’s a bit above my pay grade at the moment.

If you have two sidebars, this change will disable both of them if you add the custom field.

Don’t try to comment out the original php code and then add the above php code to your page.php file. This will result in removing your sidebar for all your pages because your new code will be ignored.

Be sure that no spaces are between the “<” and the “?php” portion of your code if you are cutting and pasting it in. Your sidebar will indeed disappear, but in its place will be a bunch of php code on your webpage. And that would be sort of ugly.

I haven’t proven this yet, but I imagine you could disable the sidebar for specific posts by modifying a different php file and then creating the custom field for a specific post.

Method 3: Disable sidebar for specific page (alternate method)

This is a faster change requiring only one step, after you’ve determined the Page ID of your specific page.

Determine the Page ID of your page

Hover over the title of your page in your Edit Pages list. The Post ID will appear in the status bar at the bottom of your browser, as pictured below.

wordpress pageid status bar

Post ID number is circled in red

Modify your page.php file

In your WordPress Editor, go to Appearance / Editor and click on page.php. Scroll down to the bottom of the file where you will see the line of code that displays your sidebar:

<?php get_sidebar(); ?>

Replace that one line with this:

<?php if ( !( is_page(‘696‘) ) ) { ?>
<?php get_sidebar(); ?>
<?php } ?>

Note that you will need to replace the red 696 post ID number above with your Post ID number.

Save the file. You’re done.

Warnings and Tips

While this change seems simpler, it isn’t advisable, particularly if you anticipate having to disable the sidebar for more than one page because you will have to go into the page.php file over and over again, thereby increasing your risk of destabilizing your theme. Speaking as a former computer programmer, it is always better to create custom fields or variables that can be easily changed as opposed to “hard coding” numbers into a program.

Method 4: Disable sidebar from all pages

This method will disable your sidebar from all pages. Not your posts, just your pages because you are only changing your pages.php file.

Modify your page.php file

In your WordPress Editor, go to Appearance / Editor and click on page.php. Scroll down to the bottom of the file where you will see the line of code that displays your sidebar:

<?php get_sidebar(); ?>

Remove this line.

Save the file. You’re done.

Other articles you might find helpful:

WordPress: How to Switch from Blogger to WordPress

How to Get Back Lost Feedburner Subscribers after Switching to WordPress

P.S. Hey, guess what? I wrote a book about writing better blog posts, written to help you kick it up a notch and make them more engaging. It’s educational as well as entertaining. It’s called Sticky Readers: How to Attract a Loyal Blog Audience by Writing More Better and you can buy it just about anywhere online. There’s more info at the Sticky Readers website, including where to buy it.

Sticky Readers, margaret andrews, write better blog posts, blogging tips

15 Comments

  1. Ansh says:

    Thanks for this great tutorial and code.. cheers

  2. Masako says:

    Thank you so much for this post Nanny Goats. You solved my problem with your method #2 instruction. I have no idea what your website is about, but I now am a big fan : )

    Masako

  3. Thanks nanny, wanted rid of them all so I went with method 4… thought that was the line that needed gone but wanted to verify. Worked perfectly.

    1. Margaret says:

      Glad it worked for you, skinny! :)

  4. Techalam says:

    First method worked for me (i.e. selecting no sidebars from page attributes. Thanks a lot :)

  5. mark says:

    Hello.
    I’ve been struggling to get a sidebar eliminated from 1 page in my blog for a while and every thing I come across fails to eliminate the sidebar (perhaps I’m cursed or something)

    here is all the code on my page.php file…

    <div class="post page" id="post-“>

        <a href="” rel=”bookmark”>

         <?php edit_post_link(__('Edit','basic2col'),'’,”); ?>
       
       
           

            <?php wp_link_pages('before=’.__(‘Pages:’,’basic2col’).’&after=’); ?>

            ID.’&echo=0′);
            if ($children) {?>
               
               
                   
               
           

       

       

       

       

    …I cannot see “” at all in this code to replace it with, ”

    You’re help on this matter to reslove this little dilema I have would be greatly appreciated.

    Thank you,

    MH

  6. Jeromerookie says:

    hello,
    thank you for this post. I use Method 2. But how can you readjust the width of the content to fill all the way across the page ?
    thanks

    1.  Sorry for the late response! But I’m afraid I don’t know how you can fill the page using Method 2. I would think that you would have to create a new template that has no sidebar in the first place and call that up, rather than merely using your main template and disabling the side bar.  Sorry I couldn’t be more help!

  7. Maria ward says:

    LOOKING FOR DOMESTICS HOUSEKEEPER RELIABLE NANNY NEEDED IN OUR HOME

    Hello

    We are a happy and noble family here in London , we have two kids Jasmine and Terry,aged 4yrs and 2yrs old, we looking for an Au pair or Nanny ,Gardener and a Driver from Any Country that can speak English and the interested should be willing to stay with us for a minimum of 2years

    About Our Family…..

    Ward thomas(father)
    Maria Ward(my wife)
    Terry Ward(son)
    Jasmine Ward(daughter)
    Home Address: 47 hopefield avenue, Paddington Brent, London NW6 6LH, UK

    We are a very happy and noble couple, My kids are fairly easy going and relaxed, they would enjoy someone with lots of energy ,enthusiasm and sense of humor.

    We only seek a Au pair for basic child care and light housework. If you accept to take a position with us, you would be paid 2500Pounds with a weekly pocket money of 200Pounds. Hence we are doing anything that would motivate the intending Nanny to put in his/her best in taking care of our child.you would be paid for overtime service if any occurs.Your feeding,accommodation,medication,payment of tax and insurance shall been take care of by us.

    kindly send us your CV or Resume to mariaward19@rocketmail.com,you can possibly add me on your yahoo messenger so that i can i have an interview with you….. Any interested applicant should make sure his or her passport and birth certificate are authenticated ones,because the documents have an important role to play in your coming down to the UK.We shall discuss travel arrangements in due course of which we would be of generous assistance to you.

    1. Hello Maria Ward. Have you seen this recent post? It’s an open letter for people just like you. I hope you find it informative and illuminating.
      http://www.nannygoatsinpanties.com/2011/11/an-open-letter-to-email-marketers-for-nanny-services.html
      Please consider this blog my resume to you.

  8. Have more of these methods stopped working since this was posted? Or would some not work depending on a particular theme being used?

    I ask because even method 3 doesn’t work for me. The pesky sidebar just keeps on showing up.

    1. A lot of it depends on which theme you’re using. Different themes could be using different php files than what I’ve specified. If a theme designer has decided to go off the tracks and create some custom php file, I wouldn’t know what the name of that custom page is. I’m using the PrimePress theme and the above methods (1 and 2 anyway) work. The best method for me is to find a theme that has “no sidebar” as an option from the WP dashboard.

  9. ralphcarlson says:

    I can think of nothing more dangerous than blogging how tos from a humor blogger. What amusing anecdotes can you collect from that I wonder.

    1. Ralph – Admittedly, I have written a few silly things under the guise of “How To”, so I should probably be careful about segregating when I'm kidding around and when I'm not. :)

  10. Arnold says:

    An interesting look at a question that is often asked by WordPress users. The use of a custom field to control the sidebar is one that I have not seen before. The new default theme in the upcoming WordPress 3 uses this same idea to control the header images.