Example 1 — Print the site ID
Show the current ID on the screen.
<p>Site ID: <?php echo get_current_blog_id(); ?></p> How It Works
- The function returns an integer.
echoprints it.- A single site always prints 1.

In WordPress, get_current_blog_id() returns the ID of the site you are on. On a normal single site, the ID is always 1.
On Multisite, every site in the network has its own ID, so this function tells you which site your code is running on.
It takes no arguments and returns a whole number.
<?php
$site_id = get_current_blog_id();
echo $site_id; | Call | What it does |
|---|---|
get_current_blog_id() | Returns the current site ID. |
switch_to_blog( 2 ) | Changes the current site to ID 2 (Multisite). |
restore_current_blog() | Goes back to the original site. |
On a single site it returns 1, so it is safe to call anywhere.
get_current_blog_id(): int | Parameter | Description |
|---|---|
| None | This function takes no parameters. |
| Return Value | Description |
|---|---|
| int | The current site ID. It is 1 on a single site. |
Three short theme examples. Each one shows the code and what it prints.
Show the current ID on the screen.
<p>Site ID: <?php echo get_current_blog_id(); ?></p> echo prints it.Keep saved data separate for each site.
<?php
$key = 'my_stats_' . get_current_blog_id();
echo $key; Read the ID inside a different site.
<?php
echo 'Before: ' . get_current_blog_id() . "\n";
switch_to_blog( 2 );
echo 'Inside: ' . get_current_blog_id() . "\n";
restore_current_blog();
echo 'After: ' . get_current_blog_id(); switch_to_blog( 2 ) moves to site 2.restore_current_blog() brings back site 1.Load footer.php or a named footer file such as footer-shop.php.
6 people found this page helpful