Forums

[resolved] Exclude Sidebar from a specific page (5 posts)

  1. gmrtech
    Member
    Posted 4 years ago #

    OK. I checked EVERYwhere and I am completely stumped.

    How can I Exclude a Sidebar from a specific page?

    I want to keep it on my home page, etc. Except for a page that I want to be only information.

    So I'm thinking it's probably very simple - like going into the index.php OR page.php file and putting something like:

    exclude_sidebar=?page_id=19

    OR something like:

    if_page_id=19?exclude_sidebar

    Please let me know exactly how I should type this, and where - I know its an easy answer, but I'm completely php-helpless.

    Thanks!

  2. Jeremy Clark
    Moderator
    Posted 4 years ago #

    In your page.php file look for the sidebar call
    <?php get_sidebar(); ?>
    Change to this code

    <?php if (is_page('1'))
    {}
    else {
    get_sidebar();
    }
    ?>

    Replace the 1 with the page id that you want to exclude the sidebar from.

  3. gmrtech
    Member
    Posted 4 years ago #

    OMG Thanks so much - worked perfectly.

    : )

  4. dropandhop
    Member
    Posted 4 years ago #

    Thanks, this was very helpful!

    However, I am trying to do a slight twist on this request. I would like my sidebar to just show up on the home page and then the usual sidebar that shows up on the blog pages.

    As such, following your instructions would take me a bit of time because I want to exclude the sidebar more then I want to include it.

    Do you have any suggestions on how to do an exclude like this?

    I also noticed that with your code the sidebar is excluded, but the space for the sidebar is still maintained. I was curious if there was a way to remove this space on the static pages which I don't use the sidebar.

    Thanks again.

    Any help is greatly appreciated,
    A

  5. karl19
    Member
    Posted 3 years ago #

    To exclude something from the frontpage and show it on all other pages, use the is_home() tag. More information about conditional tags for WordPress is here - http://codex.wordpress.org/Conditional_Tags

    As for the sidebar still taking up space, it's most likely to do with where the HTML is: if you have a HTML structure in your index.php or similar page and the sidebar gets called into this, then the structure will remain even when it's not called. Add any sidebar-related structural mark-up to the actual sidebar.php file instead and when that file is not called, the code around it wont show either.

Topic Closed

This topic has been closed to new replies.

About this Topic