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:
- Method 1: Use a WP theme that has a simple “No Sidebar” option in the main WP Editor.
- Method 2: Disable sidebar using a custom field.
- Method 3: Disable sidebar for one page by modifying one of the php files (e.g., page.php)
- 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?
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.
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.
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.
















