So this is something that I’ve never run across before, and as usual with WordPress there’s a function for that! I feel so like a TV advert right now…
One of my themes has a generated sidebar title for the default sidebar. However, on the dynamic version of this when someone chooses their widgets, it uses the standard construction inside a functions.php file via register_sidebar() to construct the structure of the widget. This is common for 99% of the themes, and would never really need to be looked at, like so:
if (function_exists(‘register_sidebar’))
register_sidebar(array(‘name’ => ‘sidebar1′,
’before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’,
’after_widget’ => ‘</li>’,
’before_title’ => ‘<h2 class=”widgettitle”>’,
’after_title’ => ‘</h2>’,
));
Clearly though, this is unacceptable when you need to generate the sidebar title and have a specific font for it, that is created from a script. It was quite difficult in finding this little known function, but Adrian Mummey has written a great article on it and shown how to use it.
So first of all, I cleaned out that sidebar registration in the functions.php file, so now it’s bare like so:
if (function_exists(‘register_sidebar’))
register_sidebar(array(‘name’ => ‘sidebar1′,
’before_widget’ => ”,
’after_widget’ => ”,
’before_title’ => ”,
’after_title’ => ”,
));
Now, further down in the same functions.php file follow Adrian’s instructions and add this:
add_filter(‘dynamic_sidebar_params’, ‘reclamation_sidebar_params’);
For me this was part of the theme I was fixing, Reclamation, so I named my function reclamation_sidebar_params(). This is where the magic is, here is that function which I fleshed out:
function reclamation_sidebar_params($params){
$params[0]['before_widget'] = ‘<div class=”block”><div class=”block_title”>’;
$params[0]['before_title'] = ‘<h3><img src=”‘ . get_bloginfo(‘stylesheet_directory’) . ‘/sidebartitles.php?letters=’ . @$params[0]['widget_name'] . ‘” />’;
$params[0]['after_widget'] = ‘</div><div class=”block_bottom”>
}
This function lets you really got to town on the sidebar parameters, which the ordinary method does not. Now with the code above as you can see, I called a php file called sidebartitles.php which created the text using a separate font. This is one method of making sure a theme uses a font regardless of whether the viewer has it on their machine.
So thanks to Adrian, this is a method to really tailor your sidebar, very useful if you’re a theme author and want to go to town on your creation.

















Trackbacks