I dont understand why my sidebar isn't changing over to the second one on the other pages. I've gone in an told the pages that if your not on this page show sidebar 2. So the home page and blog page have a sidebar 1 and the rest of the pages have sidebar 2. But it's not working.

My code on my main theme layout looks like this:

<?php if(is_page('blog')) { ?>
    <?php include(TEMPLATEPATH.'/sidebar2.php'); ?>
<?php } else { ?>
    <?php include(TEMPLATEPATH.'/sidebar.php'); ?>
<?php } ?>  

<?php get_footer(); ?>

So if I understand it correctly, if the page is blog show sidebar 1 if not show sidebar 2. I have sidebar.php and sidebar-2.php pages and they have widgets in them so I know when it's working.

Yet I don't see it doing anything. Is there something in the functions.php file I've forgotten to place in?

2 Answers 2


Your main problem is that the is_page() conditional will not return true if it is included inside or after the loop.

Your other issue which is not necessarily related to the issue at hand is the way you are including your sidebars. WordPress comes with a handy little function called get_sidebar(). If you have more than one sidebar you can pass a parameter to the function that lets it know what sidebar you want.

You need to name your sidebars sidebar-{sidebar_name}.php. So if you wanted to include sidebar1 you would name your file sidebar-sidebar1.php and to include it is simply get_sidebar( 'sidebar1' )

To solve your is_page() problem you can either call wp_reset_query() after your loop or assign the conditional return boolean to a variable before the loop then use it when including your sidebar.

//Somewhere before the loop
$page_var = is_page( 'blog' ) ? true : false;

//loop stuff

if ( $page_var ) {
     get_sidebar( 'sidebar1' );
} else { get_sidebar( 'sidebar2' ); }
  • 1
    Mostly personal preference here, but I'd use get_sidebar() for the first sidebar and then get_sidebar( 'blog' ) for the second. This uses the files sidebar.php and sidebar-blog.php. Better yet, that means sidebar.php is the fallback if sidebar-blog.php ever doesn't exist. Also, it's more semantic.
    – mrwweb
    May 27, 2012 at 18:55
  • Good point mrwweb.
    – Chris_O
    May 28, 2012 at 6:38

Do you have the blog page selected under the "Posts page" option of the "Front page displays" Reading Setting? If so then you need to update the conditional from is_page('blog') to is_home().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.