Show the Current Site ID in the Admin Bar
Shows super admins the blog ID of the site they are on in the toolbar, with links to that site's Network Admin edit screens.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
add_action( 'admin_bar_menu', function ( $bar ) {
if ( ! is_super_admin() ) {
return;
}
$id = get_current_blog_id();
$bar->add_node( array(
'id' => 'wpide-site-id',
'title' => esc_html( sprintf( 'Site #%d', $id ) ),
'href' => network_admin_url( 'site-info.php?id=' . $id ),
'meta' => array( 'title' => __( 'Edit this site in Network Admin' ) ),
) );
foreach ( array( 'site-info.php' => 'Info', 'site-users.php' => 'Users', 'site-themes.php' => 'Themes', 'site-settings.php' => 'Settings' ) as $path => $label ) {
$bar->add_node( array(
'parent' => 'wpide-site-id',
'id' => 'wpide-site-id-' . sanitize_key( $label ),
'title' => esc_html( $label ),
'href' => network_admin_url( $path . '?id=' . $id ),
) );
}
}, 999 );
Notes
Only visible to super admins.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.