Using WordPress ‘get_site’ PHP filter

The get_site WordPress PHP filter allows you to modify the site data after it has been retrieved.

Usage

add_filter( 'get_site', 'my_custom_function' );

function my_custom_function( $site_data ) {
    // your custom code here
    return $site_data;
}

Parameters

  • $site_data (WP_Site): The site data object that you can modify.

More information

See WordPress Developer Resources: get_site

Examples

Change Site Title

Modify the site title by adding a prefix:

add_filter( 'get_site', 'change_site_title' );

function change_site_title( $site_data ) {
    $site_data->blogname = 'My Prefix: ' . $site_data->blogname;
    return $site_data;
}

Add Custom Site Attribute

Add a custom attribute to the site data:

add_filter( 'get_site', 'add_custom_site_attribute' );

function add_custom_site_attribute( $site_data ) {
    $site_data->custom_attribute = 'Custom Value';
    return $site_data;
}

Change Site URL

Modify the site URL by adding a subdirectory:

add_filter( 'get_site', 'change_site_url' );

function change_site_url( $site_data ) {
    $site_data->siteurl .= '/subdirectory';
    return $site_data;
}

Modify Admin Email

Change the admin email address of the site:

add_filter( 'get_site', 'modify_admin_email' );

function modify_admin_email( $site_data ) {
    $site_data->admin_email = '[email protected]';
    return $site_data;
}

Set Site Language

Set the site language to a different language code:

add_filter( 'get_site', 'set_site_language' );

function set_site_language( $site_data ) {
    $site_data->WPLANG = 'es_ES';
    return $site_data;
}