I'm trying to add some code based on which multisite is shown. However for both the main site and sub-domains it always shows the ID as 1. I've put
$current_site = get_current_site();
var_dump($current_site);
in both the header.php and index.php and they both output the same for every sub-domain:
object(WP_Network)[275]
private 'id' => int 1
public 'domain' => string '...' (length=16)
public 'path' => string '/' (length=1)
private 'blog_id' => int 1
public 'cookie_domain' => string '...' (length=16)
public 'site_name' => string '...' (length=19)
Has anyone else ran into this issue and know of a way to get the correct current id?
I'm trying to add some code based on which multisite is shown. However for both the main site and sub-domains it always shows the ID as 1. I've put
$current_site = get_current_site();
var_dump($current_site);
in both the header.php and index.php and they both output the same for every sub-domain:
object(WP_Network)[275]
private 'id' => int 1
public 'domain' => string '...' (length=16)
public 'path' => string '/' (length=1)
private 'blog_id' => int 1
public 'cookie_domain' => string '...' (length=16)
public 'site_name' => string '...' (length=19)
Has anyone else ran into this issue and know of a way to get the correct current id?
When Multisite was first rolled into core (from a project call "multi-user", which is why you'll sometimes see references to "mu-*"), the terminology was that you'd run a site of blogs. Now we refer to a network of sites, but because the functions had all already been named, get_current_site()
gets the current network.
You'll need to use get_current_blog_id()
to get the current site's ID, or get_bloginfo()
or get_blog_details()
for more detailed data on the current site.
get_current_site