Home » Functions » settings_errors

The settings_errors function is a built-in WordPress function that is used to display error messages or feedback to users on the WordPress admin pages. This function is commonly used to display errors or notifications related to settings pages, but it can also be used to display messages on any admin page.

The function accepts a single parameter, which is the settings page ID. This parameter is optional, and if it is not provided, the function will display any errors or notifications that have been added using the add_settings_error function.

The settings_errors function can be particularly useful for plugin or theme developers who want to provide feedback to users about any changes or updates made to their product. For example, a plugin developer could use this function to display a notification to users when a new version of their plugin is available.

Here is an example usage code for the settings_errors function:

// Display any errors or notifications on the settings page
function my_plugin_settings_page() {
  // Add an error message if the user does not have permission to access the settings page
  if ( !current_user_can( 'manage_options' ) ) {
    add_settings_error( 'my-plugin-settings', esc_attr( 'settings_updated' ), __( 'You do not have permission to access this page.', 'my-plugin' ), 'error' );
  // Display any errors or notifications
  settings_errors( 'my-plugin-settings' );
  <div class="wrap">
    <h1><?php esc_html_e( 'My Plugin Settings', 'my-plugin' ); ?></h1>
    <!-- Settings form goes here -->

In this example, the function is used to display any errors or notifications on the ‘my-plugin-settings’ page. Any errors or notifications are added using the add_settings_error function, and then displayed using the settings_errors function.

Learn More on

Register an account to save your snippets or go Pro to get more features.