Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to assign a new CSS class to default widget <ul> in Page/Post creating page in WordPress. How can I do this?

See the image below.

enter image description here

share|improve this question
    
It can be declared when creating the sidebar widget holder. [I think this has been answered here.][1] [1]: stackoverflow.com/a/16885510/3252930 –  user3252930 Feb 14 at 13:52
add comment

2 Answers

Go to your function.php and find your widget code

You must add or edit that class parameters in your sidebar code like that 'class' => 'new-class',

It would be like that:

register_sidebar(array(
  'name' => __( 'Right Hand Sidebar' ),
  'id' => 'right-sidebar',
  'class'       => 'new-class',
  'description' => __( 'Widgets in this area will be shown on the right-hand side.' ),
  'before_title' => '<h1>',
  'after_title' => '</h1>'
));

You must check out Wordpress Codex for more usage

share|improve this answer
add comment

Don't edit your parent themes functions file.

register_sidebar(array(
'name'          => __( 'Sidebar name', 'theme_text_domain' ),
'id'            => 'unique-sidebar-id',
'description'   => '',
'class'         => 'add class here',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget'  => '</li>',
'before_title'  => '<h2 class="widgettitle">',
'after_title'   => '</h2>' );
));

Copy it over to your child themes functions and make the changes there or simply register a new widget.

You could then hook it in from your child themes functions like this

add_action( 'your_hook', 'new_widget' );
function new_widget() {
if ( is_your_conditional_tag() && is_active_sidebar( 'new-widget' ) ) { 
dynamic_sidebar('new-widget', array(
'before' => '<div class="new-widget">',
'after' => '</div>',
) );
    }
}

You can also add more classes to the dynamic_sidebar function.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.