Loading...


Loading...

Welcome!

Sign up for a free account, or log in here.

Member Login

You can login by following the link.

Not a Member? Sign up! It's Free!

Please feel free to register.

Click to log in.

Using dynamic_sidebar_params in WordPress Themes

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, , 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”>  $params[0]['after_title'] = '</h3></div>

 return $params;
}

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.



Leave a Reply



You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


The English Guy on Twitter

Raised Paper WordPress Theme

Raised Paper WordPress Theme screenshot
Theme Price

Onyx WordPress Theme

Onyx WordPress Theme screenshot
Theme Price

Victoriana WordPress Theme

Victoriana WordPress Theme screenshot
Theme Price

Expression Blue WordPress Theme

Expression Blue WordPress Theme screenshot
Theme Price

Premium WordPress Theme Release: Natural Green

Premium WordPress Theme Release: Natural Green screenshot
Theme Price

Theme Release: Ikon WordPress Theme

Theme Release: Ikon WordPress Theme screenshot
Theme Price

Shocking WordPress Theme Release

Shocking WordPress Theme Release screenshot
Theme Price

Digitalis WordPress Theme Release

Digitalis WordPress Theme Release screenshot
Theme Price

WordPress Theme: OpenAir Theme

WordPress Theme: OpenAir Theme screenshot
Theme Price

WordPress Theme: Very English

WordPress Theme: Very English screenshot
Theme Price

News Print v3.0 WordPress Theme Released

News Print v3.0 WordPress Theme Released screenshot
Theme Price

Reclamation WordPress Theme

Reclamation WordPress Theme screenshot
Theme Price