WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Action Reference/admin notices

This page is marked as incomplete. You can help Codex by expanding it.

Description

Notices displayed near the top of admin pages. The hook function should echo a message to be displayed.

Usage

<div class=\"{class}\"><p>{message}</p></div>

Parameters

{class}
(string) (required) The class of admin notice, updated or error or update-nag
Default: None
{message}
(string) (required) Message to show to user
Default: None

Example

function my_admin_notice() {
    ?>
    <div class="updated">
        <p><?php _e( 'Updated!', 'my-text-domain' ); ?></p>
    </div>
    <?php
}
add_action( 'admin_notices', 'my_admin_notice' );

The class "updated" will display the message with a white background and a green left border (used to be a yellow background before WordPress 3.8.). You can reference the _e function here, https://codex.wordpress.org/Function_Reference/_e

function my_admin_error_notice() {
	$class = "error";
	$message = "Error in saving";
        echo"<div class=\"$class\"> <p>$message</p></div>"; 
}
add_action( 'admin_notices', 'my_admin_error_notice' ); 

The class "error" will display the message with a white background and a red left border (used to be a red background before WordPress 3.8.).

function my_admin_error_notice() {
	$class = "update-nag";
	$message = "your message";
        echo"<div class=\"$class\"> <p>$message</p></div>"; 
}
add_action( 'admin_notices', 'my_admin_error_notice' ); 

The class "update-nag" will display the message with a white background and a yellow left border. In addition, the message will be moved above the page title (<h2>).

Related