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')) {
} else {

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)


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!

| improve this answer | |
  • is_page() works fine with slugs: @param mixed $page Page ID, title, slug, or array of such. – fuxia 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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