WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/add site option

Description

Essentially the same as add_option() but works network wide when using WP Multisite.

The only major difference is that on multisite site-wide options will not autoload and on a single site the option will autoload. Unlike when using add_option() on a single site, the feature cannot be overridden.

Usage

<?php add_site_option$option$value ); ?>

Parameters

$option
(string) (required) The name of the option to add.
Default: None
$value
(mixed) (required) The value for the option.
Default: None

Return Values

(boolean) 
Whether the option was added.

Example

Default usage:

add_site_option( 'my_option', 'my_value' );

Behavior if the option already exists:

echo get_site_option( 'i_exist_already' );

// Output: 'some_value'


if ( add_site_option( 'i_exist_already', 'new_value' ) ) {
   echo get_site_option( 'i_exist_already' );
} else {
   echo 'Already exists';
}

// Output before WP 3.3: 'new_value'
// Output after WP 3.3: 'Already exists'

Change Log

  • 3.3.0 - The behavior of the function was changed so that existing options would not be updated.
  • Since 2.8.0

Source File

add_site_option() is located in wp-includes/option.php.

Related

See also index of Function Reference and index of Template Tags.