Can a function inside the functions.php file call another function from within functions.php? I'm guessing yes and which is why I wrote the code below, but it doesn't work for some reason. Can anyone please check it out and help me.
I tried calling pageBarColor() from register_sidebar()
Thanks.
<?php
if (function_exists('register_sidebar')) {
register_sidebar(array(
'before_widget' => '<li class="sidebarModule">',
'after_widget' => '</li><!-- end module -->',
'before_title' => '<h2 class="moduleTitle '.pageBarColor().'">',
'after_title' => '</h2>',
));
}
function pageBarColor(){
if(is_category('3')) {
return "color1";
} elseif(is_category('4')) {
return "color2";
} elseif(is_category('5')) {
return "color3";
} elseif(is_category('6')) {
return "color4";
} elseif(is_category('7')) {
return "color5";
}
}
?>
The problem is probably that when you call
register_sidebar
Wordpress has not yet executed the code which determines the result ofis_category
. If you try calling yourpageBarColor
function straight after defining it you'll find it doesn't return anything. One way of working around this would be to hook into thedynamic_sidebar_params
filter (which is called when you calldynamic_sidebar
in your templates, assuming you do) and update your widgetbefore_title
values, something like this: