
The sidebar is a very important element of your blog, but sometimes, you just don’t want it to be displayed on your homepage. If you’d like to know how to do, just read this recipe.

The sidebar is a very important element of your blog, but sometimes, you just don’t want it to be displayed on your homepage. If you’d like to know how to do, just read this recipe.
To hide your sidebar on your blog homepage, edit the index.php file from your theme and look the the following:
<?php get_sidebar(); ?>
Replace it by the code above:
<?php if (!is_front_page()) {
get_sidebar();
} ?>
That's all. Your sidebar will now be displayed on all pages, exept your blog homepage.
17 Responses
Yet another great recipe. I’ve been paying around with things like this and especially for link juice funneling it can be quite useful.
One thing that I would like to ask though is whether it is possible to create code where you’re not using “is_some_page” but rather use “is_NOT_some_page”?
In php, the ! sign means “is not”. You could easily create a is_not_front_page() function, but that’s not very useful because !is_front_page() means the same thing
Oh I’m sorry I didn’t get that you were hiding it from the frontpage. Most of these guide teach how to SHOW things on the frontpage and not on the rest of the pages but this guide is the opposite. Sorry about that mistake
It’s supposed to be the holiday night or what ever. I don’t know, that’s what my girl friend is yelling at me, while I am on my computer..
..I am Jewish..IDK any better..
Any way, nice little PHP recipe. I am totally working on a custom theme for my site, and make it main stream, or I mean workable/readable.
So the site you see now is a free design I found online, to replace the old one that was to similar to another site. hopefully will see a new launch in the new year.
Keep up the good work on those great Hollywood “one liners”.
I use is_home() to control things that show or not at homepage but removing the sidebar from homepage… just remove the get_sidebar(); from the index.php or home.php file…
Why insert more code when what you need to do is remove it?
@Mario: is_home() has been deprecated. is_front_page() have the same effect.
Indeed you should remove the get_sidebar() function on index.php, but this recipe is also helpful if you’d like to remove the sidebar on any other page.
didn’t know it was deprecated. Thanks
The reason that made me comment this thread is that newbies or people that don’t understand the code, follow tutorials as they are and most of them don’t think outside the tutorial.
So saying «this is how you remove the sidebar» is not the most correct way.
A more extensive tutorial showing how to use the is_front_page(); function would be preferable.
is_home()andis_front_page()mean two different things. The former checks if it’s the page that lists your latest posts (generally the home page). The latter checks if it’s the page that’s set to your front page.I don’t think
is_home()has been deprecated becauseis_front_page()will not work if there are no pages for your site.@Justin Tadlock: I was sure is_home() has been depracated. Don’t remember who told me about it, btw.
Anyways, thanks for the excellent info!
Well at least on WordPress Codex there’s no info on is_home being deprecated
http://codex.wordpress.org/Conditional_Tags#The_Main_Page
For what I understood is_home() will act when you main blog page ,index.php or home.php is i’m not mistaken, is displayed.
is_front_page() will act when the main blog page is displayed or when another page, set to be the front page of the website, is displayed.
Seems I was wrong on this point. Thank you guys for letting me know!
maybe the one told you thought that is_home() is deprecated because there is now the is_frontpage().
Justin is correct, I use the is_frontpage() if my theme has a static page as a frontpage and is_home() for the blog post page.
The purpose of this tut is to hide the sidebar only on the frontpage or the “homepage” and not on the other pages. If we remove
the get_sidebar() in the index, yes the sidebar will not show since you remove it completely and it will not show in the other pages so theres no sense in removing get_sidebar() if we only want it to be hidden in the frontpage(“homepage”) and not in any other page.
Thanks…
Thanks for this info, interesting recipes you got up there.
I’m a newbie to WP and PHP but I have Q: Does this only hide it from the users and not the spyder/bots? or it will remove it completly from the front page…
Thanks!
@goldhead
It will completely remove the sidebar with all its content on the frontpage because it has a if conditional statement that says to php if the current page “is the front page” then do not include the code called sidebar.php.
Correct me if i’m wrong, I think the get_sidebar(); is just like a php server-side include.
ya, i’m still trying to hide the sidebar on the forum section.. i do want it on the front page..
Trackbacks: