1

I'm looking to add multiple widget areas to a page in my theme as id like to have widgets within certain pages. I can add one using this code, I'm just struggling with a second.

function new_sidebar_widget_init() {

register_sidebar( array(
    'name' => 'new-sidebar',
    'id' => 'new-sidebar',
    'before_widget' => '<div id="new-sidebar">',
    'after_widget' => '</div>',
    'before_title' => '',
    'after_title' => '',
) );
}
add_action( 'widgets_init', 'new_sidebar_widget_init' ); 

Then to place it in on my page:

<?php  dynamic_sidebar( 'new-sidebar' ); ?> 
1

You have to register multiple areas:

function new_sidebar_widget_init() {
   register_sidebar( array(
        'name' => 'new-sidebar',
        'id' => 'new-sidebar',
        'before_widget' => '<div id="new-sidebar">',
        'after_widget' => '</div>',
        'before_title' => '',
        'after_title' => '',
    ) );
    register_sidebar( array(
        'name' => 'new-sidebar-1',
        'id' => 'new-sidebar-1',
        'before_widget' => '<div id="new-sidebar">',
        'after_widget' => '</div>',
        'before_title' => '',
        'after_title' => '',
    ) );
}
add_action( 'widgets_init', 'new_sidebar_widget_init' ); 

And then you can use them based on their ID:

<?php  dynamic_sidebar( 'new-sidebar' ); ?> 

<?php  dynamic_sidebar( 'new-sidebar-1' ); ?> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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