Function: update_option

update_option( string $option, mixed $value, string | boolean $autoload )

Update the value of an option that was already added.

Shortcut: uo

You can use above key combination to trigger the associated snippet for this function in the WordPress Snippets for Visual Studio Code extension. You can also use this shortcut to search for this function on this website.

You do not need to serialize values. If the value needs to be serialized, then it will be serialized before it is inserted into the database. Remember, resources can not be serialized or added as an option.

If the option does not exist, then the option will be added with the option value, with an $autoload value of 'yes'.

Parameters

Name Type(s) Default Value Description
$option string

Option name. Expected to not be SQL-escaped.

$value mixed

Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.

$autoload string | boolean null

Optional. Whether to load the option when WordPress starts up. For existing options, $autoload can only be updated using update_option() if $value is also changed. Accepts 'yes'|true to enable or 'no'|false to disable. For non-existent options, the default value is 'yes'. Default null.

Returns

boolean

False if value was not updated and true if value was updated.

WordPress Developer Newsletter

Stay informed of new chapter releases, important WordPress API updates and more.