Title: admin_notices
Published: April 25, 2014
Last modified: February 24, 2026

---

# do_action( ‘admin_notices’ )

## In this article

 * [More Information](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#more-information)
    - [Example](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#example)
 * [Source](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#wp--skip-link--target)

Prints admin screen notices.

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#more-information)󠁿

### 󠀁[Example](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#example)󠁿

In order to display a notice, echo a div with the class `notice` _and_ one of the
following classes:

* `notice-error` – will display the message with a white background and a **red**
left border.
 * `notice-warning`– will display the message with a white background
and a **yellow/orange** left border. * `notice-success` – will display the message
with a white background and a **green** left border. * `notice-info` – will display
the message with a white background a **blue** left border. * optionally use `is-
dismissible` to add a closing icon 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.

**Don’t use `update-nag` as a class name!**
 It is not suitable for regular admin
notices, as it will apply different layout styling to the message. Additionally 
it will trigger the message to be moved above the page title (`<h1>`), thus semantically
prioritizing it above other notices which is not likely to be appropriate in a plugin
or theme context.

The inner content of the div is the message, and it’s a good idea to wrap the message
in a paragraph tag `<p>` for the correct amount of padding in the output.

    ```php
    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' );
    ```

    ```php
    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' );
    ```

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#source)󠁿

    ```php
    do_action( 'admin_notices' );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/admin-header.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/admin-header.php#L313)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/admin-header.php#L313-L313)

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#changelog)󠁿

| Version | Description | 
| [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 11 content](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#comment-content-2411)
 2.    [Patrick Johanneson](https://profiles.wordpress.org/pjohanneson/)  [  9 years ago  ](https://developer.wordpress.org/reference/hooks/admin_notices/#comment-2411)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-2411)
     Vote results for this note: 7[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-2411)
 4.  **Sample Usage**
 5.      ```php
         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' );
         ```
     
 6.  The class `notice-success` will display the message with a white background and
     a green left border.
 7.      ```php
         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' );
         ```
     
 8.  The class `notice-error` will display the message with a white background and 
     a red left border.
 9.  Use `notice-warning` for a yellow/orange, and `notice-info` for a blue left border.
 10. 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.
 11. [copied/pasted from [https://codex.wordpress.org/Plugin_API/Action_Reference/admin_notices%5D](https://codex.wordpress.org/Plugin_API/Action_Reference/admin_notices%5D)
 12.  * Other interesting classes in this context are `.notice-alt` (gives the notice
        a background hue matching the color of `.notice-info`, `.notice-success`, etc),`.
        notice-title` (formats the element as a title for the notice, useful to blend
        in with the WP style), `.notice-large` (increases the size of the notification
        box as well as its padding). [These styles were added in WordPress 4.4](https://github.com/WordPress/WordPress/commit/dd0815702411eafcccd6c0db617c69f7b18c0ddc).
      * [Bart Kuijper](https://profiles.wordpress.org/spartelfant/) [6 years ago](https://developer.wordpress.org/reference/hooks/admin_notices/#comment-3627)
 13.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%3Freplytocom%3D2411%23feedback-editor-2411)
 14.  [Skip to note 12 content](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#comment-content-5938)
 15.   [Amaan Khan](https://profiles.wordpress.org/akrocks/)  [  4 years ago  ](https://developer.wordpress.org/reference/hooks/admin_notices/#comment-5938)
 16. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-5938)
     Vote results for this note: 7[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-5938)
 17. Method to display message dynamically (Taking example of warning message)
 18.     ```php
         /**
          * Class to log warnings.
          */
         class Log_Warning {
         	/**
         	 * Message to be displayed in a warning.
         	 *
         	 * @var string
         	 */
         	private string $message;
     
         	/**
         	 * Initialize class.
         	 *
         	 * @param string $message Message to be displayed in a warning.
         	 */
         	public function __construct( string $message ) {
         		$this->message = $message;
     
         		add_action( 'admin_notices', array( $this, 'render' ) );
         	}
     
         	/**
         	 * Displays warning on the admin screen.
         	 *
         	 * @return void
         	 */
         	public function render() {
         		printf( '<div class="notice notice-warning is-dismissible"><p>Warning: %s</p></div>', esc_html( $this->message ) );
         	}
         }
         ```
     
 19. Now you can simply initialize the class to display a dynamic message.
 20.     ```php
         new Log_Warning( 'Image should contain async tag' );
         ```
     
 21.  * Nice one, want to build on that and add even more features. ` /** * Class Log_Warning**
        Displays admin notices in the WordPress dashboard. */ class Log_Warning { /***
        Message text for the notice. * * @var string */ private string $message; /***
        Notice type (info, error, success, warning). * * @var string */ private string
        $notice = 'info'; /** * Whether the notice can be dismissed. * * @var bool */
        private bool $dismissible = false; /** * Constructor. * * @param string $message
        The message to display. * @param string $notice Type of notice (default 'info').*
        @param bool $dismissible Whether notice is dismissible. */ public function 
        __construct( string $message, string $notice = 'info', bool $dismissible = 
        false ) { $this->message = $message; $this->notice = $notice; $this->dismissible
        = $dismissible; // Hook the render method into the admin_notices action. add_action('
        admin_notices', array( $this, 'render' ) ); } /** * Outputs the admin notice
        markup. * * @return void */ public function render() { printf( '%s', esc_html(
        $this->notice ), esc_html( $this->dismissible ? 'is-dismissible' : '' ), esc_html(
        $this->message ) ); } } `
      * [beezee81](https://profiles.wordpress.org/beezee81/) [7 months ago](https://developer.wordpress.org/reference/hooks/admin_notices/#comment-7402)
 22.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%3Freplytocom%3D5938%23feedback-editor-5938)
 23.  [Skip to note 13 content](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#comment-content-6786)
 24.   [jakeparis](https://profiles.wordpress.org/jakeparis/)  [  2 years ago  ](https://developer.wordpress.org/reference/hooks/admin_notices/#comment-6786)
 25. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-6786)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-6786)
 26. As of WordPress 6.4, you can output admin notice/messages with two new functions(
     which are yet to be documented):
 27. `wp_admin_notice()` and `wp_get_admin_notice()`;
 28. First parameter is your message as a string; second parameter is an args array
     with the most useful being type: `[ 'type' => 'error' ]`.
 29. So for example:
 30.     ```php
         if ( $error === true ) {
           wp_admin_notice( 'There was an error!', [ 'type' => 'error' ] );
         }
         ```
     
 31. More information:
      [https://make.wordpress.org/core/2023/10/16/introducing-admin-notice-functions-in-wordpress-6-4/](https://make.wordpress.org/core/2023/10/16/introducing-admin-notice-functions-in-wordpress-6-4/)
 32.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%3Freplytocom%3D6786%23feedback-editor-6786)
 33.  [Skip to note 14 content](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#comment-content-3387)
 34.   [Benny](https://profiles.wordpress.org/bvl/)  [  7 years ago  ](https://developer.wordpress.org/reference/hooks/admin_notices/#comment-3387)
 35. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-3387)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-3387)
 36. The Theme Review Team (TRT) released a package you can use in your theme or plugin
     to create admin notices:
      [https://github.com/WPTRT/admin-notices](https://github.com/WPTRT/admin-notices)
 37. Its primary purpose is for providing a standardized method of creating admin notices
     in a consistent manner using the default WordPress styles.
 38. Notices created using this method are automatically dismissible.
 39.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%3Freplytocom%3D3387%23feedback-editor-3387)
 40.  [Skip to note 15 content](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#comment-content-5163)
 41.   [Philipp Stracker](https://profiles.wordpress.org/strackerphil-1/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/admin_notices/#comment-5163)
 42. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-5163)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-5163)
 43. Information on the unofficial, voluntary flag `'DISABLE_NAG_NOTICES'` is missing.
     Here are relevant details from the old codex page:
 44. > **Disable Nag Notices**
     >  In late 2017, an unofficial defined constant was proposed
     > by LittleBizzy as a voluntary way for plugin or theme authors to allow for hiding
     > certain admin notices that may be considered bothersome by some webmasters. 
     > It can be used as follows:
     > `define('DISABLE_NAG_NOTICES', true);`
     > It should be noted that there is no universal support for this constant, although
     > a limited number of plugin and theme authors have begun to support it. A typical
     > use case might be for hiding recurring “nag” notices that ask users to review
     > their extension on WordPress.org, etc. Furthermore, it should not have any effect
     > on general notices that appear within WP Admin, and is simply a way for extensions
     > to opt in to disabling certain notices at their own discretion.
 45. Usage sample:
 46.     ```php
         if ( ! defined( 'DISABLE_NAG_NOTICES' ) || ! DISABLE_NAG_NOTICES ) {
         	add_action( 'admin_notices', 'my_admin_notice_renderer' );
         }
         ```
     
 47.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%3Freplytocom%3D5163%23feedback-editor-5163)
 48.  [Skip to note 16 content](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#comment-content-3865)
 49.   [jakeparis](https://profiles.wordpress.org/jakeparis/)  [  6 years ago  ](https://developer.wordpress.org/reference/hooks/admin_notices/#comment-3865)
 50. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-3865)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-3865)
 51. In order to display a notice, echo a div with the class `notice` and one of the
     following classes:
 52. * `notice-error` – will display the message with a **red** left border.
      * `notice-
     warning`– will display the message with a **yellow/orange** left border. * `notice-
     success` – will display the message with a **green** left border. * `notice-info`–
     will display the message with a **blue** left border. * optionally use `is-dismissible`
     to add a closing icon 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.
 53. **Don’t use `update-nag` as a class name!** It is not suitable for regular admin
     notices, as it will apply different layout styling to the message. Additionally
     it will trigger the message to be moved above the page title, thus semantically
     prioritizing it above other notices which is not likely to be appropriate in a
     plugin or theme context.
 54. The inner content of the div is the message, and it’s a good idea to wrap the 
     message in a paragraph tag for the correct amount of padding in the output.
 55.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%3Freplytocom%3D3865%23feedback-editor-3865)
 56.  [Skip to note 17 content](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#comment-content-5370)
 57.   [Chigozie Orunta](https://profiles.wordpress.org/chigozieorunta/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/admin_notices/#comment-5370)
 58. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-5370)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-5370)
 59. Here’s a simple way to add an independence day notice to some admin pages.
 60.     ```php
         add_action( 'admin_notices', 'independence_notice' );
     
         function independence_notice() {
             global $pagenow;
         	$admin_pages = [ 'index.php', 'edit.php', 'plugins.php' ];
             if ( in_array( $pagenow, $admin_pages ) ) {
         		if ( date( 'j, F' ) === '1, October' ) { 
         			?>
         			<div class="notice notice-warning is-dismissible">
         				<p>Happy Independence Day, Nigeria...</p>
         			</div>
         			<?
         		}
             }
         }
         ```
     
 61.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%3Freplytocom%3D5370%23feedback-editor-5370)
 62.  [Skip to note 18 content](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#comment-content-3462)
 63.   [Munir Mahmud](https://profiles.wordpress.org/mamesweb/)  [  7 years ago  ](https://developer.wordpress.org/reference/hooks/admin_notices/#comment-3462)
 64. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-3462)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-3462)
 65.     ```php
         //Display admin notices 
         function my_test_plugin_admin_notice()
         {
         	//get the current screen
         	$screen = get_current_screen();
     
         	//return if not plugin settings page 
         	//To get the exact your screen ID just do var_dump($screen)
         	if ( $screen->id !== 'toplevel_page_YOUR_PLUGIN_PAGE_SLUG') return;
     
         	//Checks if settings updated 
         	if ( isset( $_GET['settings-updated'] ) ) {
         		//if settings updated successfully 
         		if ( 'true' === $_GET['settings-updated'] ) : ?>
     
         			<div class="notice notice-success is-dismissible">
         				<p><?php _e('Congratulations! You did a very good job.', 'textdomain') ?></p>
         			</div>
     
         		<?php else : ?>
     
         			<div class="notice notice-warning is-dismissible">
         				<p><?php _e('Sorry, I can not go through this.', 'textdomain') ?></p>
         			</div>
     
         		<?php endif;
         	}
         }
         add_action( 'admin_notices', 'my_test_plugin_admin_notice' );
         ```
     
 66. The class notice-success will display the message with a white background and 
     a green left border and the class notice-error will display the message with a
     white background and a red left border.
 67. if you want to display the errors you can also use notice-warning for a yellow/
     orange for a blue left border.
 68.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%3Freplytocom%3D3462%23feedback-editor-3462)
 69.  [Skip to note 19 content](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#comment-content-6325)
 70.   [pkostadinov](https://profiles.wordpress.org/pkostadinov/)  [  3 years ago  ](https://developer.wordpress.org/reference/hooks/admin_notices/#comment-6325)
 71. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-6325)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-6325)
 72. The `admin_notices` hook doesn’t do anything on a Block Editor screen. For that
     reason you need to print it second time with JS.
 73. Here is an example, of how to make a notification that will show on Post Edit 
     Screen if Gutenberg is used:
 74.     ```php
         add_action( 'admin_notices', 'wpdocs_custom_notice' );
     
         function wpdocs_custom_notice(): void {
         	$message = 'Hello World!';
         	$type    = 'info';
     
         	if ( empty( $message ) || empty( $type ) ) {
         		return;
         	}
     
         	?>
         	<div class="notice notice-<?php echo esc_attr( $type ); ?> is-dismissible">
         		<?php echo wpautop( $message ); ?>
         	</div>
     
         	<script>
         		( function( wp ) {
         			wp.data.dispatch( 'core/notices' ).createNotice(
         				'<?php echo sanitize_text_field( $type ); ?>',
         				'<?php echo sanitize_text_field( $message ); ?>',
         				{
         					isDismissible: true,
         				}
         			);
         		} )( window.wp );
         	</script>
         	<?php
         }
         ```
     
 75.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%3Freplytocom%3D6325%23feedback-editor-6325)
 76.  [Skip to note 20 content](https://developer.wordpress.org/reference/hooks/admin_notices/?facet2=pdf&output_format=md#comment-content-6396)
 77.   [jorensm](https://profiles.wordpress.org/jorensm/)  [  3 years ago  ](https://developer.wordpress.org/reference/hooks/admin_notices/#comment-6396)
 78. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-6396)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%23comment-6396)
 79. Here is code to display a notice after a page refresh(for example after a post
     has been saved/updated).
 80.     ```php
         class WPDocsAdminNotice {
         	const NOTICE_FIELD = 'wpdocs_admin_notice_message';
     
         	public function displayAdminNotice() {
         		$option      = get_option( self::NOTICE_FIELD );
         		$message     = isset( $option['message'] ) ? $option['message'] : false;
         		$noticeLevel = ! empty( $option['notice-level'] ) ? $option['notice-level'] : 'notice-error';
     
         		if ( $message ) {
         			echo $message;
         			delete_option( self::NOTICE_FIELD );
         		}
         	}
     
         	public static function displayError( $message ) {
         		self::updateOption($message, 'notice-error');
         	}
     
         	public static function displayWarning( $message ) {
         		self::updateOption($message, 'notice-warning');
         	}
     
         	public static function displayInfo( $message ) {
         		self::updateOption($message, 'notice-info');
         	}
     
         	public static function displaySuccess( $message ) {
         		self::updateOption($message, 'notice-success');
         	}
     
         	protected static function updateOption( $message, $noticeLevel ) {
         		update_option( self::NOTICE_FIELD, array(
         			'message' => $message,
         			'notice-level' => $noticeLevel
         		) );
         	}
         }
         ```
     
 81. **Usage**
 82. Add this action at the top level of your code:
 83.     ```php
         add_action( 'admin_notices', array( new WPDocsAdminNotice(), 'displayAdminNotice' ) );
         ```
     
 84. Then use the class anywhere in your code:
 85.     ```php
         WPDocsAdminNotice::displayError( __( 'An error occurred, check logs.' ) );
         ```
     
 86.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F%3Freplytocom%3D6396%23feedback-editor-6396)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fadmin_notices%2F)
before being able to contribute a note or feedback.