How to get the name and description of a sidebar in theme?

You can use the $wp_registered_sidebars global variable. Like this:

global $wp_registered_sidebars;
if( is_active_sidebar( 'activity_calendar_en' ) ):
    esc_html_e( $wp_registered_sidebars['activity_calendar_en']['name'] );
    dynamic_sidebar( 'activity_calendar_en' );
endif;

If you check the WordPress core for is_registered_sidebar function, you’ll see that it’s using this global variable too:

function is_registered_sidebar( $sidebar_id ) {
    global $wp_registered_sidebars;

    return isset( $wp_registered_sidebars[ $sidebar_id ] );
}

However, as far as I know, you can’t retrieve it using any function.

Although, for description there is a function: wp_sidebar_description(). You may use the global variable for description as well, or this function:

if( is_active_sidebar( 'activity_calendar_en' ) ):
    echo wp_sidebar_description( 'activity_calendar_en' );
    dynamic_sidebar( 'activity_calendar_en' );
endif;

Leave a Comment

tech