How to remove the sidebar from a certain page?

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.

This entry was posted in Widget Area and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

21 Comments

  1. Pam
    Posted February 10, 2010 at 11:34 am | Permalink

    Is there any way to get this to work on the home/index page?

    • Posted February 16, 2010 at 11:03 pm | Permalink

      Yes, change the (is_page('forum')) to (is_home()).

      • ba:D
        Posted March 3, 2010 at 7:59 pm | Permalink

        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

        • Posted March 3, 2010 at 8:26 pm | Permalink

          CSS is case-sensitive. Change body.slug-Home to body.slug-home

          Chris

      • Phil
        Posted May 24, 2010 at 11:41 am | Permalink

        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.

  2. jo
    Posted March 14, 2010 at 12:15 am | Permalink

    This is great, however, is there a way to do the opposite? Remove the sidebar from all but one page.

    • Posted March 14, 2010 at 2:30 pm | Permalink

      This would be something like:


      function remove_sidebar() {
      if (!is_page('whatever')) {
      return FALSE;
      } else {
      return TRUE;
      }
      }
      add_filter('thematic_sidebar', 'remove_sidebar');

  3. Sarah Reiwitch
    Posted April 7, 2010 at 1:30 am | Permalink

    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

    • Posted April 7, 2010 at 2:33 pm | Permalink

      Hi Sarah,

      in this case you need to use:


      body.home #container {
      width: 960px;
      }

      body.home #content {
      width: 940px;
      }

      Chris

      • Sarah Reiwitch
        Posted April 7, 2010 at 7:43 pm | Permalink

        Thanks so much for replying so promptly and providing me with the answer! That did the trick.

        I really appreciate it!
        Sarah

  4. Posted April 8, 2010 at 11:45 pm | Permalink

    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.

    • Posted April 11, 2010 at 3:42 pm | Permalink

      Try:
      if (!is_page(array('1', '2'))) {

  5. Posted April 16, 2010 at 6:35 pm | Permalink

    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?

  6. Shipra
    Posted April 17, 2010 at 2:37 am | Permalink
  7. dave
    Posted April 18, 2010 at 9:08 pm | Permalink

    brill code, thanks Chris. the last bit was exactly what i was after.

  8. Posted May 2, 2010 at 11:20 am | Permalink

    you are a genius. thank you so much!

  9. Posted June 5, 2010 at 1:03 pm | Permalink

    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.

  10. Posted June 14, 2010 at 3:19 am | Permalink

    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?

    • Posted June 23, 2010 at 9:45 pm | Permalink

      Ok, after spending over a week with this problem, I stumbled upon a solution myself.

  11. egarcia
    Posted July 15, 2010 at 4:43 pm | Permalink

    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?

  12. egarcia
    Posted July 15, 2010 at 5:06 pm | Permalink

    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);

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Latest via Twitter

@DeFries .. will be there as long as they offer Frikandel & Pommes Special ;)

More in Widget Area (3 of 3 articles)