WordPress get_current_blog_id() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Multisite helper

Definition

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.

Syntax

It takes no arguments and returns a whole number.

WordPress
<?php
$site_id = get_current_blog_id();
echo $site_id;
CallWhat 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.

Full declaration
WordPress
get_current_blog_id(): int

Parameters

ParameterDescription
NoneThis function takes no parameters.

Return Value

Return ValueDescription
intThe current site ID. It is 1 on a single site.

WordPress Examples

Three short theme examples. Each one shows the code and what it prints.

Example 1 — Print the site ID

Show the current ID on the screen.

WordPress
<p>Site ID: <?php echo get_current_blog_id(); ?></p>

How It Works

  1. The function returns an integer.
  2. echo prints it.
  3. A single site always prints 1.

Example 2 — Build a cache key per site

Keep saved data separate for each site.

WordPress
<?php
$key = 'my_stats_' . get_current_blog_id();
echo $key;

How It Works

  1. We add the site ID to the end of a name.
  2. Each site gets its own key.
  3. Data from one site will not mix with another.

Example 3 — Switch sites and restore

Read the ID inside a different site.

WordPress
<?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();

How It Works

  1. switch_to_blog( 2 ) moves to site 2.
  2. The ID now returns 2.
  3. restore_current_blog() brings back site 1.

Frequently Asked Questions

It returns the ID of the current site as an integer.
It returns 1.
No. It works on every install, and it is useful for plugins that support both single sites and Multisite.
Use switch_to_blog() to move to that site, then call get_current_blog_id(). Call restore_current_blog() when you are done.

Next: get_footer()

Load footer.php or a named footer file such as footer-shop.php.

get_footer() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful