Let's say I have this code in my "functions.php":

function mytheme_widgets_init() {
    register_sidebar( array(
        'name'          => esc_html__( 'Sidebar Name', 'mytheme' ),
        'id'            => 'sidebar-2',
        'description'   => '',
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );
add_action( 'widgets_init', 'mytheme_widgets_init' );

How can I get that sidebar name by its id, some kind of this code?

get_dynamic_sidebar_name( 'sidebar-2' ); // -> Sidebar Name

1 Answer 1


Sidebars are stored in global variable $wp_registered_sidebars. You can get the sidebar properties using this variable.

global $wp_registered_sidebars;
if ( isset( $wp_registered_sidebars['sidebar-2'] ) ) { 
    echo $wp_registered_sidebars['sidebar-2']['name'];

Note that do not use it too early, either on/after widgets_init hook or in a template file.

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.