The add_site_meta() WordPress PHP function adds metadata to a specific site.
Usage
Here’s a simple example of how to use the add_site_meta() function. This function takes the ID of the site to which you want to add metadata, the name of the metadata, the metadata value, and an optional Boolean value to indicate whether the metadata key should be unique.
add_site_meta( $site_id, 'Example Key', 'Example Value', true );
Parameters
- $site_id (int) – The ID of the site to which you want to add metadata.
- $meta_key (string) – The name of the metadata you want to add.
- $meta_value (mixed) – The value of the metadata you want to add. It must be serializable if non-scalar.
- $unique (bool, optional) – Whether the same key should not be added. Defaults to false.
More information
See WordPress Developer Resources: add_site_meta()
This function was introduced in WordPress 3.0.
Examples
Add Site Description
// This code adds a site description metadata to a site with ID 1 add_site_meta( 1, 'site_description', 'This is a sample site', true );
Add Site Owner Information
// This code adds a site owner's email as metadata to a site with ID 2 add_site_meta( 2, 'site_owner_email', '[email protected]', true );
Add Site SEO Metadata
// This code adds SEO keywords to a site with ID 3 add_site_meta( 3, 'seo_keywords', 'keyword1, keyword2, keyword3', false );
Add Google Analytics Code
// This code adds a Google Analytics tracking ID to a site with ID 4 add_site_meta( 4, 'ga_tracking_id', 'UA-000000-1', true );
Add Social Media Profiles
// This code adds social media profiles as metadata to a site with ID 5 $social_profiles = array( 'facebook' => 'https://facebook.com/example', 'twitter' => 'https://twitter.com/example', 'linkedin' => 'https://linkedin.com/in/example' ); add_site_meta( 5, 'social_profiles', serialize($social_profiles), true );