// you’re reading...

development

Override dynamic sidebar widget defaults in Wordpress

I have been trying to freshen up and clean my design a bit, and wanted to slim down all the references to “widget” in the CSS class definitions in the dynamic sidebar. I found an excellent article on opensourcemaven detailing how to do this.

Basically you override the function call in the dynamic sidebar that registers your sidebars, and modify the default values. so that you keep modifications within your own theme directory so as not to mess with the default code.

Example code:

<?php
if ( function_exists('register_sidebar') )
 register_sidebars(2,array(
   // Removes <li> with class declaration
   'before_widget' => '<li>',
   // Removes </li> with class declaration
   'after_widget' => '</li>',
   // Replaces <h2> with class declaration
   'before_title' => '<h3>',
   // Replaces </h2> with class declaration
   'after_title' => '</h3>',
    ));
?>

No related posts.

Discussion

3 comments for “Override dynamic sidebar widget defaults in Wordpress”

  1. excellent, not only exactly what I was trying to remember how I did the first time, but the first google hit.
    thanks.

    Posted by gary | January 12, 2008, 1:19 am
  2. but how if we use a div tag before widget started ? help me, I am trying to modify my current themes.

    Posted by dr.emi | September 13, 2008, 3:27 pm
  3. hmm - have you tried copying one of the <li> lines and replacing with <div> other than that I’m not sure really!

    Posted by Al | September 18, 2008, 6:19 pm

Post a comment

Related Posts

No related posts.