WordPress.org

Ready to get started?Download WordPress

Forums

Can I remove the sidebar this way? (5 posts)

  1. codeblue2k
    Member
    Posted 5 years ago #

    I am hoping to remove my sidebar on everything besides my home page. After reading a few different post I think I have a game plan, but wanted to run it by you all to make sure that I am not missing anything.

    1) Create a home.php
    2) Copy everything thats in index.php into home.php
    3) Remove <?php get_sidebar(); ?> from index.php and page.php

    If I am reading these other posts correctly this should remove the sidebar on everything besides my home page. Am I correct or dead wrong? :)

    Is there anything else that these changes will have an effect on?

    Any info you can give me would be much appreciated.

  2. codeblue2k
    Member
    Posted 5 years ago #

    I actually went a different way... I decided that I only need to remove the sidebar from one page. So I replaced the current tag that calls the sidebar with:

    <?php if (is_page('X')) : ?>
    <?php else : ?>
    <?php get_sidebar(); ?>
    <?php endif; ?>

    X being the page ID number that I want to exclude the side bar from. But I came up with a slight different problem. How do I reclaim the space where the side bar was located for the body of the page?

  3. Len
    Member
    Posted 5 years ago #

    Your approach is correct but of course now you have this ugly empty space where the sidebar used to be. :) That's easy to fix. You simply have to adjust your stylesheet. Look at the default Kubrick theme to see how it accomplishes this. Notice the content DIV on index.php and single.php uses different classes?

    <div id="content" class="narrowcolumn">

    <div id="content" class="widecolumn">

    Study the differences between these 2 in the stylesheet. It's not that hard to wrap your head around it.

  4. codeblue2k
    Member
    Posted 5 years ago #

    Awesome thanks for the info!!

    I actually just got it going before you posted. What I ended up doing is using that same if/else statement for two different style sheets. So if page ID is X then use this style sheet, else use the standard. Changed the width on the new style sheet to 100%.

    See any long term issues with that?

  5. Len
    Member
    Posted 5 years ago #

    See any long term issues with that?

    Nah. You can use all the stylesheets you want. They aren't actually downloaded on a visitor's browser until needed so it won't affect load time.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.