WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/add site option

Contents

Description

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

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:

// Before 3.3
echo get_site_option( 'i_exist_already' );
// 'foo'

if ( add_site_option( 'i_exist_already', 'some_value' ) ) {

   echo get_site_option( 'i_exist_already' );

} else {

   echo 'Already exists';
}

// 'some_value'

// After 3.3
if ( add_site_option( 'i_exist_already', 'some_value' ) ) {

   echo get_site_option( 'i_exist_already' );

} else {

   echo 'Already exists';
}

// '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.