Title: Dynamic class for widget element
Last modified: August 19, 2016

---

# Dynamic class for widget element

 *  Resolved [oldcastle](https://wordpress.org/support/users/oldcastle/)
 * (@oldcastle)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/dynamic-class-for-widget-element/)
 * Hi,
 * I don’t know the best way to explain this, so I will try my best.
 * Usually we register a sidebar with a code like this
 *     ```
       register_sidebar(
       		array(
       	 		'name' => 'Secondary Widget Area',
       	 		'id'=> 'secundary_sidebar',
       	 		'before_widget' => '<div class="widget">',
       			'after_widget' => '</div>',
       			'before_title' => '<h3 class="widgettitle">',
       			'after_title' => '</h3>',
       		)
       	);
       ```
   
 * And when we use it, it will generate this HTML:
 *     ```
       <div class="widget">
       <h3 class="widgettitle">
       ......
       ```
   
 * So, my question is. How can I generate automatically a specific class name in
   my widget?
 * The reason is for me to be able to style my widgets easily.
 * Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [oldcastle](https://wordpress.org/support/users/oldcastle/)
 * (@oldcastle)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/dynamic-class-for-widget-element/#post-1656700)
 * Any help here?
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/dynamic-class-for-widget-element/#post-1656808)
 * usually, the kubrick default does it with:
 *     ```
       if ( function_exists('register_sidebar') ) {
       	register_sidebar(array(
       		'before_widget' => '<li id="%1$s" class="widget %2$s">',
       		'after_widget' => '</li>',
       		'before_title' => '<h2 class="widgettitle">',
       		'after_title' => '</h2>',
       	));
       }
       ```
   
 * have you tried to read the docu:
    [http://codex.wordpress.org/Function_Reference/register_sidebar](http://codex.wordpress.org/Function_Reference/register_sidebar)
 *  Thread Starter [oldcastle](https://wordpress.org/support/users/oldcastle/)
 * (@oldcastle)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/dynamic-class-for-widget-element/#post-1656871)
 * Thank you very much!
 * Resolved!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Dynamic class for widget element’ is closed to new replies.

## Tags

 * [class](https://wordpress.org/support/topic-tag/class/)
 * [widget](https://wordpress.org/support/topic-tag/widget/)

 * 3 replies
 * 2 participants
 * Last reply from: [oldcastle](https://wordpress.org/support/users/oldcastle/)
 * Last activity: [15 years, 9 months ago](https://wordpress.org/support/topic/dynamic-class-for-widget-element/#post-1656871)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
