How to remove sidebar on 1 page, and keep it on the others? This was a question asked in the forums the other day and upon answering it I thought to myself what interesting fodder for another post! I supplied the original poster with 2 methods on how to achieve the result but in this post I’ll concentrate on the 2nd option.
In WordPress, a Page is used to display information other than regular posts and it lives outside of the normal blog chronology. In the default Kubrick theme there are 3 Page Templates that can be used to display the content of a Page:
- page.php – Default Page Template, displays Page content
- archives.php – ignores Page content and instead displays a list of Archives
- links.php – ignores Page content and instead displays your links
So which Template does WordPress use to display the content of a particular Page? WP will search your theme’s files for templates and use the first one it finds in this order:
- The Page’s selected Page Template
- page.php
- index.php
Now you probably don’t want to remove the sidebar from page.php because that will remove it from ALL Pages using that Template. So, we simply create a new Page Template and assign it to the Page that you don’t want the sidebar to appear in. This is not as difficult as it sounds. Simply create a duplicate of your theme’s page.php but leave out the call to the sidebar. In the default Kubrick theme the tag that calls the sidebar is …
<?php get_sidebar(); ?>
My theme is a little different. I have 2 sidebars and they are called as …
<?php include (TEMPLATEPATH . '/second.php'); ?>
<?php include (TEMPLATEPATH . '/third.php'); ?>
… but we’ll stick to using the first tag. Open up your theme’s page.php and copy/paste the contents into a new file. Leave out the tag that calls the sidebar. Using the example provided by the Codex, place this at the very top of your new file …
<?php
/*
Template Name: Snarfer
*/
?>
… and save it as snarfer.php. Upload the new Template to your theme directory. Now, when you create a new Page you simply assign your new Page Template – in this case snarfer.php – to display its content.
Of course after doing this you may want to make further adjustments since you will now be left with a strange looking empty space where the sidebar used to be. You will probably want to widen the content area so that if fills that empty space. All you need to do is rename the DIV that holds your content in your new Page Template then add its styling attributes to your style sheet. You can see how this is done by studying the differences between index.php and single.php in the default Kubrick theme. Notice how one uses class=”narrowcolumn” and the other uses class=”widecolumn”.
If you want to see a live example of this in action click here. [demo currently unavailable]
Update: After reading this post I thought perhaps that I would include the other option I provided in the forum for the benefit of anyone reading this in the event you don’t see that forum post. This option for removing the sidebar from a certain Page involves the use of conditional tags. Look in your theme’s page.php for the sidebar call. Once again, using Kubrick as an example, that would be …
<?php get_sidebar(); ?>
… and add a few lines of code around it so that it now looks like this …
<?php if (is_page('x')) : ?>
<?php else : ?>
<?php get_sidebar(); ?>
<?php endif; ?>
… where “x” is the ID number of that Page. What this says is “if we are on page “x” do nothing and if not get the sidebar”. While this method may be easier I prefer creating a new Page Template. Anyway, you now have 2 methods to hide your sidebar on certain Pages.
Further reading:
http://codex.wordpress.org/Pages
http://codex.wordpress.org/Pages#Page_Templates
http://codex.wordpress.org/Conditional_Tags

When comes to WordPress, in future I need to refer to you as my ‘guru”
Like I said earlier, I’m no guru. Just another WP user who is addicted to the software.
Len,
I have been trying to get rid of the sidebars on WordPress Essence page for over a week. Following your instructions for creating a new page template and deleting the sidebar call worked. I had tried to do this before but the new template did not show in the Page Attributes template dropdown list.
Thanks for the help.
You’re welcome Judy.
My site template has the get_sidebar commands in the footer. It is called with:
How would you recommend making it go away on my forum.php page
is_page_template(‘forum.php’)
I am barely a novice at PHP.
Oops, system took out my code. Anyway it is called with an include TEMPLATEPATH command.
Hi Pammy. What theme are you using? I’ll have a look.
Hi! This was very helpful to me. The only problem I have is renaming the DIV in order to adjust the width. I don’t know how to do that. Can someone point me in the right direction?
Hi Karen,
Exactly what are you trying to accomplish and what theme are you using?
I am trying to use your second method as I am a novice. I did your steps and it almost worked but I am left with the original width. How do I change that for one page? This is the page I am stuck with at the moment.
http://mikecandoit.com/?page_id=309
Thanks for the help.
I actually figured it out. Often the simple solution is where it is. I was trying so hard to figure how to change the setting of the page and then realized when I have pictures too large they overlap the sidebar. So I changed the embed code from 100% to 900px. Simplify, simplify. But thanks to your code I figured it out.
Mike
Glad to see you figured it out Mike.
Hello there. I’ve a bit of a problem concerning removing my sidebar from my template. You see, I don’t have the get_sidebar function in my template. The theme I’m using apparently calls a dynamic sidebar for the pages, and I’ve no clue how to get rid of it for this one page. Any help?
Hi Ashley,
What theme are you using?
Gr8 article , I will keep this as the last option for what I am trying to achieve.
What I really want to do is disable Adsense ads shown in the sidebar from a certain page and show some other ad in place of that. Do you recon that this is possible ?
Figured out how to do it
It can be done using is_page()
more info : http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page
Hi Saijo
The beauty of dynamic code such as PHP and the way it works with WordPress is you can achieve almost anything. Glad to see you figured it out.
thanks for this post.. was trying to hide the sidebar from google search results..
Glad you found the info useful.
Hi,
Thanks for your advice, but how can I hide the sidebar on different pages.
Using your example below I have tried to hide the sidebar on pages 2,8 16 but it will not work…..
Any tips or advice for a newbie?
Hi Worlo,
Which method are you using as I outlined 2 different ways – I suspect the 2nd. If so you need to use a “elseif” statement if you want to exclude more than one page.
Hi Len,
Correct the 2nd option. I tried using the elseif statement outlined below but it would not work for me….. any thoughts on where I am going wrong ?
I did not include “” in the below example as the code reason did not appear in my last post for some reason.
php if (is_page(’2,8,16′)) :
php else :
php get_sidebar();
php endif;
Hi Worlo,
Try adding this to the very top of page.php
<?php get_header(); ?><?php if (is_page('2')):
elseif (is_page('8')):
elseif (is_page('16')): ?>
<?php else : ?>
<?php get_sidebar(); ?>
<?php endif; ?>
This will only work if those pages are using page.php. If you have built custom template files to display those pages you’ll have to go with the first option.
Hi Len,
Thanks very much. Your code did excatly what I wanted. Excellent.
Another question for you – sorry!
When I select a nav button from the main nav menu at the top of the site the nav button selected changes colour and stays this colour until another main nav bar button is selected which is exactly what I need.
Now my side bar only appears when the “About Us” main nav bar button is selected. However when ever I select a link from the side bar the “about us” button on the main nav bar no longer has a different background colour.
In short what I am trying to do is when any of the links on the side bar is selected, I would like to the “about us” button on the main nav bar stay a different colout to show the user that they are still within the “about us” section….
Any thoughts on how I can do this???
Hmm, I’m not sure I understand. You have a page called About Us? What link in the sidebar are you clicking. I suspect this link takes you to somewhere other than About Us.
Hi Len,
I have a horizontal nav bar at the top of my site. When I click on “about us” which is a nav button on the horizontal nav bar the sidebar appears. Based on your advice above the side bar only appears when the “about us” pages is selected.
When I click on a page link from the side bar menu, I would like the “aboutus” nav button to stay shaded to let people know they are still within the “about us” section of the site……
Any thoughts…
If you’re referring to “dynamic highlighting” you may want to take a look at this post.
How To Build Horizontal Menu
In it I describe how to use dynamic highlighting.
thank you for this information, it helped me greatly!
You’re welcome Steve.
Len, I’m hoping you can help me with an issue that I’m running into. I went with your second option to take out the sidebar on a particular page. There is another page which I need to do so. How do I go about adding multiple pages to that second technique in order to kill the sidebar?
A add-on to that question is the page I need the sidebar taken out of, has a built in “sidebar-projects” section which I would like to keep.
here is the code in my page.php file
ID, $key, true) != 'wide')&&(get_post_meta($post->ID, $key, true) != 'project-view') )
{
get_sidebar();
}
elseif (get_post_meta($post->ID, $key, true) == 'project-view')
{
include ('sidebar_projects.php');
}
?>
I would appreciate any input.
Thanks,
Steve
I’m sorry, not all the code came over
ID, $key, true) != 'wide')&&(get_post_meta($post->ID, $key, true) != 'project-view') )
{
get_sidebar();
}
elseif (get_post_meta($post->ID, $key, true) == 'project-view')
{
include ('sidebar_projects.php');
}
?>
Hi Steve.
To do this for multiple pages you would need to use an
elseifstatement. For example,<?php if (is_page('123')) : elseif (is_page('456')); ?><?php else : ?>
<?php get_sidebar(); ?>
<?php endif; ?>
You can add as many pages as you like by using the
elseifstatement. With respect to your second question I’m not sure I understand. Perhaps it might be easier simply to create a new page template for that page then call that specific sidebar in it.ugghh, I’m not sure why all the code is not coming over, please delete my two previous posts. I have figured out how to hide the sidebar on, one page, and saw in the comments above how to hide it on two, but on some specific pages I have a template where there is a sidebar_projects.php that I need to have shown. Any idea on how to accomplish that?
Thank you.
I would just create new page templates for those pages and call that sidebar with them.
I used the second option. The first one doesn’t work, when adding a new page it won’t let me choose which template to use. I’m running WordPress on my own webserver.
Hi Dennis,
It’s odd that the first option doesn’t work as it’s a built-in WordPress feature. Glad to see you got it going with the 2nd option.
Hi,
I have this theme http://www.webdesignlessons.com/dynablue-wordpress-theme/
And i can’t find anything as mentioned above in the page.php file,
can you help me please ?
Hi Mena.
I had a quick look at that theme. The sidebar is actually called in footer.php. I’ll have a closer look tomorrow when I have more time.
Okay, Thank you very much.
You’re cool. I was following your instruction and figured out that the template I’m using iNove has an alternate page titled “page without sidebar”. It gives me the option to use this template in the drop down under template.
Glad you got it all sorted out Nick.
You’re welcome Mena.
Mena,
This theme will require ALOT of work to achieve the result you want because it uses a series of background images. You would have to create a new series of graphics.
Having said that, to get rid of the sidebar on certain pages we do so by creating a new Page Template and an alternate footer.php file.
First of all, create a new Page Template which can be an exact copy of your theme’s page.php. For sake of simplicity let’s call it nosidebar.php although you can call it whatever you want. At the very top of nosidebar.php insert the following …
Next, make a copy of your theme’s footer.php and call it myfooter.php (again, it doesn’t matter what you call it) In the newly created myfooter.php delete the following …
Next, go back to nosidebar.php and look for
<?php get_footer(); ?>and replace it with<?php include (TEMPLATEPATH . '/myfooter.php'); ?>So, what we have done is create a new Page Template which calls a new footer file. When you write a new page (or edit an existing one) you should be able to select the new Page Template from the drop down menu. That new Page Template will not call footer.php but WILL call myfooter.php which omits the call to the sidebar. However it will look a tad strange. You can see what I mean by clicking here.
As I said earlier, the reason for that is this theme uses a series of background images, namely
bgr_body.gif,bgr_body_end.pngandbgr_body_top.png. All of those images would have to be recreated and the style sheet adjusted for the calls to the new images. This means ALOT of work. You’re probably better off with finding a new theme.Anyway, you can find copies of the files you’ll need at the WordPress Pastebin. Just click the links.
nosidebar.php
myfooter.php
Thank you very much, maybe i will use another themes, actually lately i’m between many themes and trying this and this, and wish to find out a good one, maybe i will create my own after learning wordpress codex although i tried before with no result
But the way you have mentioned is very cool, i really loved it.
Thank you agian,
Mena
You’re welcome Mena. Good luck.
Just another comment of praise โ this was exactly what I was looking for. Worked like a charm.
Thanks!
Glad it worked for you!
Thanks for the tip! You put me on the right track!
Youโre welcome Andy.
Hi
Thanks for the โeasy to doโ tutorial.
That is great.
If you like, you can see how it looks here: http://rummycity.com/gin-tutorial/
Each template have different code for the sidebars, so just pay more attention to the code you deleting.
Beside that, itโs really good and useful.
Amit.
Nice work Amit.
After breaking my head for 3 days trying to create a google custom search page, I had finally given up. Today, again I thought, why not give it one more try. I googled for removing sidebar, came across your post, got the funda clear and finally set it up.
When you said โThis is not as difficult as it soundsโ, it really built up my confidence.
Your writing style is simple and informative. It makes my conviction strong โ SIMPLICITY RULES.
Thanks a lot, keep rocking!!
โฆwhile I move on to your about page.
Glad I could be of help Gouri. By the way, I tested your custom search page โ nice work.
Sorry for asking this question on an old post, but i want to remove the sidebar from a specific post using option 2, so would I just do this in my singlepost.php file:
And my next question is how do you get the content area to fit the whole page using option 2. i donโt want the blank white space where the sidebar was.
Thanks for your help!!
Hi Tory, no need to apologize. Thatโs the reason why I havenโt closed replies on older posts. Some of them still generate alot of interest. I would have gotten back to you sooner but I had a hernia attack Monday morning and Iโve been in agony since. Hopefully it will be over soon.
Anyway, on to your question. (and what a great question) I hadnโt thought about doing this for a particular post. Obviously Page Templates wonโt work here as WordPress will be using single.php.
I havenโt tested this code but it should work. First, you want to set up 2 different classes or IDs. You can take a look at the Kubrick theme to see how this works. Notice how that theme uses the class โnarrowcolumnโ for index.php and the class โwidecolumnโ for single.php?
Look in the single.php for the call to the sidebar. It will look something likeโฆ
<?php get_sidebar(); ?>In place of that we insert our first condition as suchโฆ
<?php if (!is_single('x')) : get_sidebar(); endif; ?>What that says is if we are on single.php and viewing the post with the ID of x (youโll have to insert the numerical ID of the actual post there) do nothing ELSE get the sidebar. So far so good.
Now we have to create another conditional. This all depends on how your theme is structured. Iโll use the generic โcontentโ ID. Look in single.php forโฆ
<div id="content">and replace with the following,
<div id="<?php if (!is_single('x')) : ?>content<?php else : ?>contentwide<?php endif; ?>">Basically what that says is if we are on single.php and viewing the post x (where x is the numerical ID of the actual post) we switch the ID content to the ID contentwide. Then you simply go in to your style sheet and set your definitions for #contentwide
Len, Get well Soon.
Thanks Gouri. After nearly a week Iโm starting to feel better.
Hello! Great post!
In regards to the blank space where the sidebar used to be, you can just delete the “div id” of the column used for your sidebar (directly from your new page template) and that will widen your content.
Tho’ I’m nOt sure if that’ll work on all themes!
Hi Virg, thanks for stopping by. Yeah depending on how the theme is constructed it may not work.
hi all!
i have installed simple press forum plugin in my blog. the forum page has still sidebar at left. please help! i need to get forum page rid of sidebar and increse forum width!
cheers faizan
Hi faizan,
Where did you get the theme from so that I can have a look at it?
i searched for free motorcycle themes and it came out to be one in google! the designers site is http://www.webmasterdeveloper.com tnx for your concern and you can see the forum tab at the top of my site. but i have not yet activated my simplepress plugin. just waiting to disable the sidebar on that page first!
Hmmm, this is not a standard WordPress theme. It was created by software known as Artisteer and as such contains a bunch of “junk”. Not sure if I can do anything but I’ll have a go.
thanks about that. can you tell me a a good source of standard wp themes, especially for motorcycle blog. sry i am asking abt it here, hope you dont mind!
thanks
Any theme can be used for a motorcycle blog. All you need is a nice header image. Here are a few sites where you can check out some great free themes.
1. Weblog Tools Collection (direct link to New Theme Releases section of their forum)
2. Smashing Magazine (link)
3. ThemeLab (link)
4. BlogOhBlog (link)
thanks…thanks a lot for your responses!
You’re welcome.
“Hmmm, this is not a standard WordPress theme. It was created by software known as Artisteer and as such contains a bunch of “junk”. Not sure if I can do anything but I’ll have a go.”
Hi there, did you find any solution on how to disable the sidebar and get the content area instead of that?
thx
Hi zec,
The original post was written quite some time ago. I don’t even recall what the theme in question looks like now. Here’s a link to a similar question in the Artisteer forums.
http://www.artisteer.com/?post_id=100503&p=forum_post&topicsPage=20&forum_id=13
I just wanted to thank you and say that the edited option worked for me…conditional tags were simple to use.
Thanks!
You’re welcome Mike.
Hey Len,
I am trying to follow your steps however my page.php file does not have the “get sidebar” code. Instead, I found it in the footer.php file. How can I make it work?
Van
I actually figured that out through your comments above, now I have a different question:
How can I achieve that for a certain post? I’m not quite sure since the get_sidebar is in my footer.php
Hope you can help me.
Van
Hi Van
Sorry for the delay in replying. The roofing season is in full swing and I’m swamped at work. Not much time for online fun.
Could you give me a link to the theme you’re using so I can have a look at it?
Hi Len,
I’ve used this method successfully, but for some reason I can’t get it to work for multiple pages…only a single page. I think I’m coding it wrong.
I did this:
So basically I wanted to remove the sidebar on page “x” and page “y”. How do I go about doing that, since the comma isn’t working.
For the record, I can block just page “x” using this method. I figured a comma separating pages would work.
Thanks so much!
Colin
It removed the code from my previous comment, but the code I was referring to was listed right below:
“… and add a few lines of code around it so that it now looks like this …”
Hi Colin
For multiple pages you will need to use an
elseifstatement. Have a look at my earlier comment to Steve and see if that helps.FYI, I think you need the “;” to be a “:” on the first line for the code to work properly.
I’m not following Colin. Referencing the comment I linked to above, I am using a
:Did I slip up somewhere else? I can’t find it.
Aahh….Should have scanned the comments better.
Thank you for your easy to understand directions, much appreciated!!
This particular post has generated a lot of comments. It’s easy to overlook something.
Hi Len,
Had been looking for a way to remove the sidebar. Thanks for the useful info. I think I will go for the second option you posted as it seems a bit simpler.
Hi Ray,
Let me know how it works out for you.
Len top post but what i need is a little bit different, what if i had a forum e.g
http://www.gloopy.co.uk/forum/
is there a simple way to exclude all of the pages after the /forum/ because doing these manually is not appropriate. I am only a newbie so please don’t laugh if this is a silly question.
I read somewhere that adding $ represents all files in a certain category but not sure.
Hi Gloopy,
Not sure I understand the question. You only need to create one Page Template then assign the applicable pages to use it as opposed to using the default page.php template file.
Hello Gloopy,
First of all, thank you for your help with the sidebar issue. I have been able to remove the side bar from one of my pages. But now that I have done this, I can’t seem to enlarge the content area. What can I do to fix this? I hope you can see what I mean…
http://frugalshoppin.com/?page_id=342
Hi Mary Lou.
Are you directing your question at me or Gloopy? Also, apologies for not seeing your comment sooner. It somehow ended up in the spam bin.
Hi Len,
I found this blog very helpful for getting rid of the sidebar on a page. I used the conditional approach which removed the sidebar but didn’t free up the space or reformat the page. I am using a theme that has hide/display sidebar functionality. The default unfortunately is to display the sidebar and then the user can hide it by clicking on the “Hide sidebar” button. Because of this default the sidebar hides but doesn’t free up the space until you click on the sidebar button again turning it into “Show sidebar” which then lets the page reset and use up the extra space. I would appreciate any suggestions on how to fix this problem by either adding something to free up the space or turning the default action for the sidebar to “Hide”.
Hi Ralph,
Without seeing that theme I can almost guarantee it is using javascript to do that. Unfortunately I am javascript-challenged.
Hi Len,
Thanks, for the help anyway. I am using the jeans theme from WPart.org. The site is at http://michaelgrandesarizona.com/. Please check it out and maybe the page source might give you some clues. If it is javascript, I’ll hunt through the code and see if I can make a change to it. I am also javascript-challenged, but at least I’ll have a direction to move in.
Thanks again for your time. I have bookmarked your page and I’ll checking it out on a regular basis from now on.
Hi Ralph,
The magic seems to be happening in this file …
wp-content/themes/jeans/js/sidebar.jsHi Len,
Thanks again. I’ll see what I can glean from your information. You have been most helpful and I appreciate your efforts.
On a different note, I also have a problem in my online store that I am working on. I am using the wp-online-store plugin and seem to be having a problem with what appears to be a table border I would imagine. There is a “previous/next” button choice that seems to display with a boundary box that completely extends off the right side of the page. I can send you an image with the problem, but apparently not in this comment box, if you would like to see it. I haven’t activated the store online yet and am working with it in a dev environment so you cannot see it from there, but if can send a way to send it to you I would be glad too.
As you can see I am brand new to WordPress. I have done most of my work in Dreamweaver with links to other pages for different things. I like the WordPress idea as it offers a backend and plugins for easier maintenance.
Hi Ralph,
I’ve never used that plugin. But you could post a link to a screenshot if you want.
Hi Len,
Unfortunately, I am working on it in a dev environment and do not have an active page on the site yet. Is there a way embed a screenshot into this reply process or include a file upload?
Hi Ralph
For safety reasons I don’t believe WordPress allows that. There may be plugins out there that alter that behaviour – I’ve never researched it.