How to get the main blog’s id and db prefix from a mu plugin?

How can one get the blog ID as well as the database prefix of the main blog in a wordpress multisite installation? Is the main blog’s ID always 1? Also how can the main blog’s table prefix be acquired from within the mu-plugin’s code?

4 s
4

Use the constant BLOG_ID_CURRENT_SITE. And to get the database table prefix, use;

$main_blog_prefix = $wpdb->get_blog_prefix(BLOG_ID_CURRENT_SITE);

Leave a Comment