Using WordPress ‘all_admin_notices’ PHP action

The all_admin_notices WordPress PHP action is used to display generic admin screen notices.

Usage

add_action('all_admin_notices', 'your_custom_function');
function your_custom_function() {
    // your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: all_admin_notices

Examples

Display a simple success message

This example shows how to display a simple success message on the admin screen.

add_action('all_admin_notices', 'display_success_message');
function display_success_message() {
    echo '<div class="notice notice-success is-dismissible"><p>Your settings have been saved successfully!</p></div>';
}

Display a warning message with a specific class

This example shows how to display a warning message with a custom CSS class.

add_action('all_admin_notices', 'display_warning_message');
function display_warning_message() {
    echo '<div class="notice notice-warning custom-class"><p>Please check your settings for errors.</p></div>';
}

Display a custom error message

This example shows how to display a custom error message on the admin screen.

add_action('all_admin_notices', 'display_error_message');
function display_error_message() {
    echo '<div class="notice notice-error"><p>There was an error with your submission. Please try again.</p></div>';
}

Display a message based on GET parameter

This example shows how to display a message based on the value of a GET parameter.

add_action('all_admin_notices', 'display_message_from_get');
function display_message_from_get() {
    if (isset($_GET['your_custom_message'])) {
        echo '<div class="notice notice-info"><p>' . esc_html($_GET['your_custom_message']) . '</p></div>';
    }
}

Display a message on a specific admin page

This example shows how to display a message only on a specific admin page.

add_action('all_admin_notices', 'display_message_on_specific_page');
function display_message_on_specific_page() {
    global $pagenow;
    if ($pagenow === 'options-general.php') {
        echo '<div class="notice notice-info"><p>This is a message displayed on the General Settings page.</p></div>';
    }
}