After installing a Gallery Plugin or a Forum Plugin you might want to remove the sidebar (Primary Aside and Secondary Aside) to gain more space for the plugin’s output.
In my example for this task, I’m going to remove the sidebar from my page ‘Forum’.
The major requirement for this and all other code snippets: You have to use a child theme!
We start with the child theme’s functions.php and add the following code:
// filter thematic_sidebar() .. no display for the page 'Forum', keep it for the rest
function remove_sidebar() {
// We test if we are on the page 'Forum'
if (is_page('forum')) {
// Yes, we are .. now we switch off the sidebar
return FALSE;
} else {
// we are not .. we leave the switch on
return TRUE;
}
}
// Connect the filter to thematic_sidebar()
add_filter('thematic_sidebar', 'remove_sidebar');
Now that we’re able to switch off the sidebar for the page ‘Forum’, we need to make the gained space available for our content.
We open the child theme’s style.css and add the following code:
body.slug-forum #container {
width: 960px;
}
body.slug-forum #content {
width: 940px;
}
Please note that this modification is related to the 2c-r-fixed layout. You might want to change the width settings according to your own design.
You can modify the conditions in remove_sidebar() to your needs … more details about <a title=”WordPress – Conditional Tags” href=”http://codex.wordpress.org/Conditional_Tags” target=”_self”>Conditional Tags</a>.
Tested with<a title=”Thematic, A WordPress Theme Framework” href=”http://themeshaper.com/thematic/”> Thematic 0.9</a> and a basic child theme.
Please use the <a title=”ThemeShaper Forums” href=”http://themeshaper.com/forums/”>ThemeShaper Forums</a> for any further questions.
21 Comments
Is there any way to get this to work on the home/index page?
Yes, change the
(is_page('forum'))to(is_home()).hi,
i’m using thematic and commune child theme.
Thanks to this post on my homepage sidebars are actually off
i added in style.css of the child theme :
body.slug-Home #container {
width: 960px;
}
body.slug-Home #content {
width: 940px;
}
but content and container keep displaying at width:620px.
what’s wrong?
Thank you for your amazing work
CSS is case-sensitive. Change
body.slug-Hometobody.slug-homeChris
Note that is_home() is picky when it comes to static pages. See http://codex.wordpress.org/Conditional_Tags#The_Main_Page to see when is_home() returns TRUE.
For a static home page, is_front_page() might be a better choice.
This is great, however, is there a way to do the opposite? Remove the sidebar from all but one page.
This would be something like:
function remove_sidebar() {
if (!is_page('whatever')) {
return FALSE;
} else {
return TRUE;
}
}
add_filter('thematic_sidebar', 'remove_sidebar');
Hi,
I was able to get rid of my sidebar on the homepage, but can’t seem to make the home page container and content pick up the style from the following that I put in my child style.css:
body.slug-home #container {
width: 960px;
}
body.slug-home #content {
width: 940px;
}
When I inspect both the container and content divs on the home page using firebug it shows the container as:
#container {
float:left;
width:620px;
}
from 2c-r-fixed.css (line 30)
and the content from my child style.css:
#content {
margin:0 0 0 40px;
overflow:hidden;
width:540px;
}
The only way that I can get the width of the content to be wider is by modifying #content and #container, but that widens all the other pages as well, not just the home page content.
Do you have any idea as to what might be wrong?
Thanks so much for your terrific work.
Thanks in advance for any help you can provide.
Sarah
Hi Sarah,
in this case you need to use:
body.home #container {
width: 960px;
}
body.home #content {
width: 940px;
}
Chris
Thanks so much for replying so promptly and providing me with the answer! That did the trick.
I really appreciate it!
Sarah
How would one go about removing the sidebar for say two pages?
I have tried:
function remove_sidebar() {
if (!is_page(’1′)(’2′)) {
return FALSE;
} else {
return TRUE;
}
}
add_filter(‘thematic_sidebar’, ‘remove_sidebar’);
but it has failed. Thanks in advance for any help.
Try:
if (!is_page(array('1', '2'))) {Thanks for this forum! I had another variation for the question – What if I want to get rid off “only” the primary aside on the home page?
I found your answer here (thanks!):
http://themeshaper.com/forums/topic/sidebar-on-all-pages-but-homepage
brill code, thanks Chris. the last bit was exactly what i was after.
you are a genius. thank you so much!
Chris,
Thank you for the straight forward answers and code. I needed to do exactly this (remove sidebars on one page) and it worked perfectly. Now, another question…
I have blog-title and sf-menu on the same baseline in the header, or so it appears visually, with #branding and #access overlapping. Since #access is on top it’s keeping the blog-title link from working. How can I simply move sf-menu into the #branding div and delete #access? I tried to work backwards through the templates but it seems that everything it constructed with functions such that I cannot simply move divs or copy PHP code from one div to another. Please explain how to move stuff around. Thanks.
Hello Chris,
I’m trying to use the style.css to make the colors on my header and footer extend all the way out to the edge of my browser. Just as if it were a liquid layout. I’m new to PHP, and I’m having the hardest time making the colors extend out to the edge of the browser.
I am using the Thematic Options child theme, which I found online and downloaded for WordPress. I also had to change my server’s PHP from 4.4.9 to PHP 5 so that the theme would work.
Can you please point me to the right code and where to change it in the style.css, etc?
Ok, after spending over a week with this problem, I stumbled upon a solution myself.
I’ve been able to remove the sidebar from the home page.
I was wondering if it’s possible to do the same with the menu bar (called “access” on thematic-lingo, I believe).
It seems that there are no “filters” for “filtering out” the access bar. How would you go about filtering out the menu bar then?
mm I think I found a solution:
function remove_access_action() {
remove_action('thematic_header','thematic_access',9);
}
add_action('init', 'remove_access_action');
function splendeo_access() {
if (!is_home()) {
return thematic_access();
}
}
add_action('thematic_header','splendeo_access',9);