View Blog ID in WordPress Multisite
April 5th, 2011 by Frank • WordPress Hacks • 10 Comments
When you work quite a bit with WordPress Multisites, sometimes you need the IDs for some functions or Plugins. The easiest way is via the hover effect with your mouse or you use a little code snippet to add a column with the ID in the table view.

The following code belongs into a Plugin and should be placed in the folder mu-plugins.
class Add_Blog_ID {
public static function init() {
$class = __CLASS__ ;
if ( empty( $GLOBALS[ $class ] ) )
$GLOBALS[ $class ] = new $class;
}
public function __construct() {
add_filter( 'wpmu_blogs_columns', array( $this, 'get_id' ) );
add_action( 'manage_sites_custom_column', array( $this, 'add_columns' ), 10, 2 );
add_action( 'manage_blogs_custom_column', array( $this, 'add_columns' ), 10, 2 );
add_action( 'admin_footer', array( $this, 'add_style' ) );
}
public function add_columns( $column_name, $blog_id ) {
if ( 'blog_id' === $column_name )
echo $blog_id;
return $column_name;
}
// Add in a column header
public function get_id( $columns ) {
$columns['blog_id'] = __('ID');
return $columns;
}
public function add_style() {
echo '<style>#blog_id { width:7%; }</style>';
}
}
add_action( 'init', array( 'Add_Blog_ID', 'init' ) );
Alternative you can use the follow plugin with this feature and also list the user ID on network view. You can download the plugin in this GIST 3832632.
Info
- Published in WordPress Hacks
- Tags: backend, Code, Multisite, PHP, WordPress, WP, WP3.0, wp3.1
- Comment feed
- read: 27368 | today: 27
- leave a Comment


Hey there, i'd really like to use this, but I don't understand this line: The following code belongs into a Plugin and should be placed in the folder mu-plugins.
Please clarify?
Hey Michael,
The mu-plugins folder is one that operates similarly to the plugins folder, but any plugin in it is automatically activated across your network. It stands for "must-use".
It is not a folder that comes with your install, so you need to manually create it.
You can read more about it on Justin Tadlock's article
@brian: thanks for this great comment to Michaels questions.
@frank
No problem : )
And nice snippet. Bookmarked. I bet I'll be needing this in an upcoming project.
Thanks for following up. Just a FYI, i didn't recieve a notification that you answered my question even thought I clicked the "Notify me of followup comments" button on the form.. It may have gone to my spam, but just so you know :D
i don't understand... there is already a colum with ID : http://archiparmentier.com/admin.jpg
@sebastian: this is not default; maybe you have active a domain-mapping plugin?
yes franck, that's it, you're right !