2
votes

I just learned how to create a custom WordPress theme. I would like to assign a class to my sidebar for styling, but I have not found anything online that explains how to do this. The code I added to my functions.php file to register my sidebar is:

    if ( function_exists('register_sidebar') )
    register_sidebar(array(
        'id'            => 'sidebar-1',
        'description'   => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ),
        'before_widget' => '',
        'after_widget'  => '',
        'before_title'  => '',
        'after_title'   => '',
    ));

And the code I added to my sidebar.php file is:

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<?php endif; ?>

Any help would be greatly appreciated!

2

2 Answers

1
votes

Use before_widget and after_widget to add a wrapper.

1
votes
register_sidebar( array(
        'name'          => esc_html__( 'Sidebar', 'twentysixteen' ),
        'id'            => 'sidebar-1',
        'description'   => 'Add widgets here to appear in your sidebar.',
        'before_widget' => '<aside id="%1$s" class="widget custom-class %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h2 class="widget-title custom-class">',
        'after_title'   => '</h2>',
    ) );

Try this in functions.php file