Function: add_settings_error

add_settings_error( string $setting, string $code, string $message, string $type )

Register a settings error to be displayed to the user.

Shortcut: ase

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.

Part of the Settings API. Use this to show messages to users about settings validation problems, missing settings or anything else.

Settings errors should be added inside the $sanitize_callback function defined in register_setting() for a given setting to give feedback about the submission.

By default messages will show immediately after the submission that generated the error. Additional calls to settings_errors() can be used to show errors even when the settings page is first accessed.

Parameters

Name Type(s) Default Value Description
$setting string

Slug title of the setting to which this error applies.

$code string

Slug-name to identify the error. Used as part of 'id' attribute in HTML output.

$message string

The formatted message text to display to the user (will be shown inside styled <div> and <p> tags).

$type string 'error'

Optional. Message type, controls HTML class. Accepts 'error' or 'updated'. Default 'error'.

WordPress Developer Newsletter

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