I have a sidebar displaying in the home and single pages. When it shows up in the home page, it has an already defined css class (width:30%)
When it shows up in the single page, i want to add/insert a new class to that sidebar. I want this new style to modify the predifined elements.So it ends with a width of 35%
I tried to do it as follows:
In functions.php (child theme)
function sidebar_class() {
if ( is_single() ) {
$class = 'sidebar-single';
}
return $class;
}
In sidebar.php
<div id="secondary" class="sidebar1-area <?php sidebar_class(); ?>" role="complementary">
The html result should be:
<div id="secondary" class="sidebar1-area sidebar-single" role="complementary">
Original css values for the class
width: 30%
Final result
width:35%
How can I accomplish this in the most efficient way?
body_class()
properly you could just style.single #secondary