do_action( 'admin_notices' )

Prints admin screen notices.


Description Description


Source Source

File: wp-admin/admin-header.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Patrick

    Sample Usage

    function sample_admin_notice__success() {
        ?>
        <div class="notice notice-success is-dismissible">
            <p><?php _e( 'Done!', 'sample-text-domain' ); ?></p>
        </div>
        <?php
    }
    add_action( 'admin_notices', 'sample_admin_notice__success' );

    The class notice-success will display the message with a white background and a green left border.

    function sample_admin_notice__error() {
    	$class = 'notice notice-error';
    	$message = __( 'Irks! An error has occurred.', 'sample-text-domain' );
    
    	printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); 
    }
    add_action( 'admin_notices', 'sample_admin_notice__error' );

    The class notice-error will display the message with a white background and a red left border.

    Use notice-warning for a yellow/orange, and notice-info for a blue left border.

    The class name is-dismissible will automatically trigger a closing icon to be added to your message via JavaScript. Its behavior, however, applies only on the current screen. It will not prevent a message from re-appearing once the page re-loads, or another page is loaded.

    [copied/pasted from https://codex.wordpress.org/Plugin_API/Action_Reference/admin_notices%5D

You must log in before being able to contribute a note or feedback.