get_site()
Retrieves site data from a network by its ID. If no argument is specified, retrieves the current site.
The result is stored in the cache and passed through the get_site filter.
Use get_sites() to retrieve a list of sites by criteria.
The function is not defined in a regular (non-multisite) installation. Calling it causes a fatal error:
Fatal error: Uncaught Error: Call to undefined function get_site()
Uses: WP_Site::get_instance()
Used By: wp_initialize_site()
Hooks from the function
Returns
WP_Site|null.
- WP_Site - site object.
null- if a site with the specified ID is not found.
Usage
get_site( $site );
- $site(WP_Site|int|null)
- Site object or ID. If the value is empty, the current site's ID is used.
Default: null
Examples
#1 Get the current site's data
$site = get_site(); /* $site = WP_Site Object ( [blog_id] => 1 [domain] => exmaple.com [path] => / [site_id] => 1 [registered] => 2018-07-11 10:49:32 [last_updated] => 2026-09-23 12:21:20 [public] => 1 [archived] => 0 [mature] => 0 [spam] => 0 [deleted] => 0 [lang_id] => 0 ) */
#2 Get a site by ID
$site = get_site( 3 );
if ( $site ) {
echo esc_html( $site->path ); //> /subsite
}Changelog
| Since 4.6.0 | Introduced. |