The populate_site_meta WordPress PHP filter allows you to modify the metadata of a site when it’s created.
Usage
add_filter('populate_site_meta', 'my_custom_populate_site_meta', 10, 2); function my_custom_populate_site_meta($meta, $site_id) { // Your custom code here return $meta; }
Parameters
$meta
(array) – Associative array of site meta keys and values to be inserted.$site_id
(int) – ID of the site to populate.
More information
See WordPress Developer Resources: populate_site_meta
Examples
Add a custom site meta value
Adds a custom site meta value called my_theme_color
with a default value of #000000
.
add_filter('populate_site_meta', 'add_my_theme_color', 10, 2); function add_my_theme_color($meta, $site_id) { $meta['my_theme_color'] = '#000000'; return $meta; }
Set a custom timezone
Sets a custom timezone for the new site.
add_filter('populate_site_meta', 'set_custom_timezone', 10, 2); function set_custom_timezone($meta, $site_id) { $meta['timezone_string'] = 'America/New_York'; return $meta; }
Add multiple custom meta values
Adds multiple custom meta values to the new site.
add_filter('populate_site_meta', 'add_multiple_custom_meta', 10, 2); function add_multiple_custom_meta($meta, $site_id) { $meta['custom_key_1'] = 'value_1'; $meta['custom_key_2'] = 'value_2'; return $meta; }
Set a custom site logo
Sets a custom site logo URL for the new site.
add_filter('populate_site_meta', 'set_custom_site_logo', 10, 2); function set_custom_site_logo($meta, $site_id) { $meta['custom_logo'] = 'https://example.com/path/to/logo.png'; return $meta; }
Modify an existing meta value
Modifies an existing meta value, for example, changing the default blog name.
add_filter('populate_site_meta', 'modify_existing_meta_value', 10, 2); function modify_existing_meta_value($meta, $site_id) { if (isset($meta['blogname'])) { $meta['blogname'] = 'My Custom Site'; } return $meta; }