I wish to alter the class names from the sidebar icons on every different category page of WordPress and that i figured the easiest method to do this is to create a function in functions.php with the conditions and return the needed class title. Then i known as the function within the list tags from the register_sidebar function.

if (function_exists('register_sidebar')) {
   '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 whatever reason the above mentioned does not work. Help


I believe register_sidebars is known as too soon along the way, once the category isn't defined yet. Perhaps you have attempted applying the dynamic_sidebar_params filter? I possibly could not find anything within the WordPress Codex, however i found this nice example. Your other question about this subject also offers a complete answer.

This only works should you implement the sidebars using dynamic_sidebar inside your widget, because this function calls the dynamic_sidebar_params filter. For those who have static icons (defined inside your template, not while using widget admin page), you need to give a call for your function for the reason that template code, such as this:

<li class="sidebarModule">
<h2 class="moduleTitle <?php echo set_widget_title_color(); ?>">Widget title</h2>
<?php /* Your widget code */ ?>
</li><!-- end module -->