I want to change the class names of the sidebar widgets on every different category page of WordPress and I figured the best way to do this would be to make a function in functions.php with all the conditions and return the required class name. I then called the function in the list tags of the register_sidebar function.
if (function_exists('register_sidebar')) {
register_sidebar(array(
'before_widget' => '<li class="sidebarModule">',
'after_widget' => '</li><!-- end module -->',
'before_title' => '<h2 class="moduleTitle "'.set_widget_title_color().'>',
'after_title' => '</h2>',
));
}
function set_widget_title_color() {
if(is_category('technology')) {
$color = "catNavColor1_active";
} elseif(is_category('gadgets')) {
$color = "catNavColor2_active";
} elseif(is_category('social-media')) {
$color = "catNavColor3_active";
} elseif(is_category('gaming')) {
$color = "catNavColor4_active";
} elseif(is_category('other')) {
$color = "catNavColor5_active";
}
return $color;
}
For some reason the above doesn't work. Please Help
Thanks