Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have 2 sidebars(primary and secondary). I want the secondary sidebar to display only on the blog page and primary sidebar to display everywhere else except for the blog page. What have I tried:

In functions.php :

if (is_page('blog-35')) {
    get_sidebar('secondary');
} else {
    get_sidebar('primary');
}

Unfortunately this doesn't work. Any hints on how to debug this? I don't understand what am I doing wrong in the code above.(blog-35 is the body class of the page I want to display only the secondary sidebar)

share|improve this question
add comment

1 Answer

First: is_page() expects a page id, so the call would be is_page(35).

Second: get_sidebar needs to be called from the template (not the functions file).

You probably already have two templates setup:

  • page.php - In here you'll call get_sidebar('primary');

  • index.php (assuming your blog is on the home page) - In here you'll call get_sidebar('secondary');

Please let me know if this answers your questions!

share|improve this answer
    
is_page() works fine with slugs: @param mixed $page Page ID, title, slug, or array of such. –  toscho Apr 27 '13 at 18:54
    
I was unaware of the slug usage with is_page ... turns out you can also use page title. That's why I love Stack Exchange, forever learning something new –  Pizaul Apr 27 '13 at 22:55
    
did moving your calls from functions.php to the appropriate template file solve your problem? –  Pizaul Apr 27 '13 at 22:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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