WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Ok for subdomain it's easy. I guess it just looks up the subdomain:


=> explode('.', $_SERVER['REQUEST_URI'])...

But how does it do it for sub-directory setups? This should be interesting considering that pages, taxonomies and what not can take the first part of the part after the site domain name.

How can it distinguish between a inner blog, and a page of the primary blog? The only thing I could think of is database matching against the entire blog list, then if it fails match primary blog content, but that would be a really stupid thing to do because it seriously slows down the site...

share|improve this question

You can use the get_current_site() function.

Ref. : http://codex.wordpress.org/WPMU_Functions/get_current_site

share|improve this answer

Your answer is in ms-settings.php, and it's basically the same for domain and/or subdirectory installs.

$current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path ) );

Both the domain name and the path are used to determine what blog is being accessed.

This doesn't "seriously slow down" anything, both the domain and the path are fully indexed fields in the database.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.