I’m working on a site with two templates, one that’s called sidebartemplate.php and one that’s called page.php. Most of the pages on my site use sidebartemplate.php, only one uses page.php.
Sidebartemplate.php has the content on the right 70% of the screen, and calls get_sidebar(), which displays the sidebar on the left 30% of the screen. Works fine.
One page has content which is far too large to fit in the right 70%, but works fine in 100%. So, I went into page.php and removed the get_sidebar() function. Now the sidebar doesn’t show up, but the “primary” div still only gets 70% of the space. I went into Inspect Element in Chrome and found that it was pulling the CSS rule for “.left-sidebar #primary”, but it should only be pulling from “#primary”, since there is no left sidebar on this particular template. It’s getting the left-sidebar from the body declaration:
<body class="page page-id-174 page-template-default logged-in admin-bar single-author singular two-column left-sidebar">
Which I believe is generated from header.php:
<body <?php body_class(); ?>>
So basically I want to modify what body_class() returns based on template. When using sidebartemplate.php, body_class() should return what it’s already returning. When using page.php, body_class() should return what it’s returning without the two-column or left-sidebar tags.
Any advice on how to get this to work?
- The topic ‘Remove "left-sidebar" from body_class() list in one template only’ is closed to new replies.