Title: Introducing admin notice functions in WordPress 6.4
Author: Colin Stewart
Published: October 16, 2023
Last modified: November 6, 2023

---

 [  ](https://profiles.wordpress.org/costdev/) [Colin Stewart](https://profiles.wordpress.org/costdev/)
3:23 pm _on_ October 16, 2023     
Tags: [6-4 ( 78 )](https://make.wordpress.org/core/tag/6-4/),
[dev-notes ( 647 )](https://make.wordpress.org/core/tag/dev-notes/), [dev-notes-6.4 ( 17 )](https://make.wordpress.org/core/tag/dev-notes-6-4/)

# Introducing admin notice functions in WordPress 6.4

Adminadmin (and super admin) notices are widely used within WordPress CoreCore Core
is the set of software required to run WordPress. The Core Development Team builds
WordPress. and in the extender community. Admin notices have common markup patterns
and CSSCSS Cascading Style Sheets. classes, but required maintaining HTMLHTML HyperText
Markup Language. The semantic scripting language primarily used for outputting content
in web browsers. independently for each notice throughout a project.

In [#57791](https://core.trac.wordpress.org/ticket/57791), two new functions were
proposed: `wp_get_admin_notice()` and `wp_admin_notice()`.

These functions abstract the HTML markup generation to reduce the maintenance burden,
encourage consistency, and enable argument and message filtering for all admin notices.
In addition, a new `wp_admin_notice` action has been introduced, which fires before
a notice is output.

## New functions

### wp_get_admin_notice()

 * Returns the markup for an admin notice.
 * Note: The markup is not fully escaped and care should be taken to select the 
   appropriate escaping function before output.

### wp_admin_notice()

 * Outputs the markup for an admin notice.
 * Markup is created using `wp_get_admin_notice()` and escaped using [wp_kses_post()](https://developer.wordpress.org/reference/functions/wp_kses_post/)
   before output.

### Parameters

Both functions have the following parameters:

 * `string $message` The message for the notice.
 * `array $args` An array of arguments for the notice.
    - `string $type` Optional. The type of admin notice. This will be appended to`'
      notice-'` to create the HTML class name. For example, a type of `'success'`
      will produce a `'notice-success'` HTML class. Default empty string.
    - `bool $dismissible` Optional. Whether the notice is dismissible. Default false.
    - `string $id` Optional. The value for the HTML `id` attribute. Default empty
      string.
    - `array $additional_classes` Optional. An array of additional class names to
      use for the notice. These are used as provided. Default empty array.
    - `array $attributes` Optional. An associative array of HTML attributes for 
      the notice. Boolean `true` attributes may just include the name of the attribute.
      Default empty array.
    - `bool $paragraph_wrap` Optional. Whether to wrap the message in `<p></p>` 
      tags. Default true.

### Filters

`wp_get_admin_notice()` applies the following filters:

 * `wp_admin_notice_args` – Filters the arguments for an admin notice.
    - Passed arguments: `array $args`, `string $message`
 * `wp_admin_notice_markup` – Filters the markup for an admin notice.
    - Passed arguments: `string $markup`, `string $message`, `array $args`

### Actions

`wp_admin_notice()` fires the following action:

 * `wp_admin_notice` – Fires before an admin notice is output.
    - Passed arguments: `string $message`, `array $args`

## Example usage

### Output a dismissible success notice

    ```notranslate
    wp_admin_notice(
      __( 'Plugin update failed.', 'my-text-domain' ),
      array(
        'type'               => 'error',
        'dismissible'        => true,
        'additional_classes' => array( 'inline', 'notice-alt' ),
        'attributes'         => array( 'data-slug' => 'plugin-slug' )
      )
    );
    ```

**Result**

    ```notranslate
    <div class="notice notice-error is-dismissible inline notice-alt" data-slug="plugin-slug"><p>Plugin update failed.</p></div>
    ```

### Create a collection of notices to output at once 

    ```notranslate
    $output = '';
    foreach ( $success_messages as $message ) {
      $output .= wp_get_admin_notice(
        $message,
        array( 'type' => 'success' )
      );
    }

    echo wp_kses_post( $output );
    ```

**Result**

    ```notranslate
    <div class="notice notice-success"><p>Success message 1</p></div>
    ```

(repeated for each notice)

### Add a class to every ‘warning’ admin notice

    ```notranslate
    add_filter( 'wp_admin_notice_args', 'myprefix_add_class_to_warnings' );
    function myprefix_add_class_to_warnings( $args ) {
      if ( 'warning' === $args['type'] ) {
        $args['additional_classes'][] = 'my-class';
      }

      return $args;
    }
    ```

**Result**

    ```notranslate
    <div class="notice notice-warning my-class"><p>Warning message 1</p></div>
    ```

(repeated for each warning notice)

## Usage in WordPress Core

The new admin notice functions have been implemented in most locations in WordPress
Core. Further work will be done in WordPress 6.5 to complete the process and migrate
older notices (using the `'updated'` and `'error'` classes) to the current admin
notice pattern (`'notice-success'`, `'notice-info'`, `'notice-warning'`, and `'notice-
error'`).

_Props to [@joedolson](https://profiles.wordpress.org/joedolson/) and [@webcommsat](https://profiles.wordpress.org/webcommsat/)
for peer review._

[#6-4](https://make.wordpress.org/core/tag/6-4/), [#dev-notes](https://make.wordpress.org/core/tag/dev-notes/),
[#dev-notes-6-4](https://make.wordpress.org/core/tag/dev-notes-6-4/)

### Share this:

 * [  Threads ](https://make.wordpress.org/core/2023/10/16/introducing-admin-notice-functions-in-wordpress-6-4/?share=threads)
 * [  Mastodon ](https://make.wordpress.org/core/2023/10/16/introducing-admin-notice-functions-in-wordpress-6-4/?share=mastodon)
 * [  Bluesky ](https://make.wordpress.org/core/2023/10/16/introducing-admin-notice-functions-in-wordpress-6-4/?share=bluesky)
 * [  X ](https://make.wordpress.org/core/2023/10/16/introducing-admin-notice-functions-in-wordpress-6-4/?share=x)
 * [  Facebook ](https://make.wordpress.org/core/2023/10/16/introducing-admin-notice-functions-in-wordpress-6-4/?share=facebook)
 * [  LinkedIn ](https://make.wordpress.org/core/2023/10/16/introducing-admin-notice-functions-in-wordpress-6-4/?share=linkedin)

 1.  ![](https://secure.gravatar.com/avatar/34f5ae0466a3b4c1a7c2745cd313eb2314872b72460f6cf345cfbcc126a140ec?
     s=32&d=mm&r=g)
 2.   [Thomas M](https://profiles.wordpress.org/webzunft/)  2:39 pm _on_ October 19,
     2023
 3.  Can I use this in my pluginPlugin A plugin is a piece of software containing a
     group of functions that can be added to a WordPress website. They can extend functionality
     or add new features to your WordPress websites. WordPress plugins are written 
     in the PHP programming language and integrate seamlessly with WordPress. These
     can be free in the WordPress.org Plugin Directory [https://wordpress.org/plugins/](https://wordpress.org/plugins/)
     or can be cost-based plugin from a third-party. and set dismissible: true, and
     expect coreCore Core is the set of software required to run WordPress. The Core
     Development Team builds WordPress. to handle closing my custom notice?
 4.   * ![](https://secure.gravatar.com/avatar/d6d6254d551f10047c16ac27288de32bfa5d96a399f1bcf618ac6b49656424f7?
        s=32&d=mm&r=g)
      *  [Chris Reynolds](https://profiles.wordpress.org/jazzs3quence/)  4:37 pm _on_
        October 23, 2023
      * [@webzunft](https://profiles.wordpress.org/webzunft/) I just tested this and
        the dismissal behavior is the same as it always has been, specifically that
        clicking the `x` makes the notice go away, but return on a refresh. So, if 
        you were hoping to get a solution to make the notice go away _permanently_,
        you’ll still need to implement something that hooksHooks In WordPress theme
        and development, hooks are functions that can be applied to an action or a 
        Filter in WordPress. Actions are functions performed when a certain event occurs
        in WordPress. Filters allow you to modify certain functions. Arguments used
        to hook both filters and actions look the same. into user metaMeta Meta is 
        a term that refers to the inside workings of a group. For us, this is the team
        that works on internal WordPress sites like WordCamp Central and Make WordPress.
        or an option for that.
      * ![](https://secure.gravatar.com/avatar/6b6d1c4d29f1b149da0008917c70b019408d5af404a46bca853e4dd33546e1ed?
        s=32&d=mm&r=g)
      *  [Joost de Valk](https://profiles.wordpress.org/joostdevalk/)  9:34 am _on_
        October 24, 2023
      * Came here to ask this exact question. I’d love to see this made more feature
        complete for 6.5, as it’d allow tons of pluginPlugin A plugin is a piece of
        software containing a group of functions that can be added to a WordPress website.
        They can extend functionality or add new features to your WordPress websites.
        WordPress plugins are written in the PHP programming language and integrate
        seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory
        [https://wordpress.org/plugins/](https://wordpress.org/plugins/) or can be 
        cost-based plugin from a third-party. developers to get rid of their own implementation
        for this and brings us one step closer to a proper notification manager.
         - ![](https://secure.gravatar.com/avatar/2915e1013f968e0a0272b4d95ca3296049b5e4e53ae8a3cad515780e59b69adc?
           s=32&d=mm&r=g)
         -  [jakeparis](https://profiles.wordpress.org/jakeparis/)  2:59 pm _on_ October
           25, 2023
         - What Joost said. This is a _huge_ win for reducing repetitive implementations
           of something coreCore Core is the set of software required to run WordPress.
           The Core Development Team builds WordPress. really should have been handling
           all along. Hooray!
         - ![](https://secure.gravatar.com/avatar/6b7f92a39d487191250a8b0b846bf29bd12cc150b28b7364ccbbd2a88e1467f6?
           s=32&d=mm&r=g)
         -  [123host](https://profiles.wordpress.org/123host/)  5:07 am _on_ October
           26, 2023
         - Not only that, but it will ultimately make users happy when WP can handle
           permanent dismissal of notifications better.
      * ![](https://secure.gravatar.com/avatar/4fd344e387cd0febbb417ee2a2bef7db6b40c8f7ecf4265fb41dcef8e9fa8c4b?
        s=32&d=mm&r=g)
      *  [Joe Dolson](https://profiles.wordpress.org/joedolson/)  6:13 pm _on_ October
        26, 2023
      * The goal for the initial release here is to replicate what already existed 
        in coreCore Core is the set of software required to run WordPress. The Core
        Development Team builds WordPress., but provide a framework for improvements
        in 6.5 and forwarded. So yes, those are 100% in the works, as are improvements
        to the accessibilityAccessibility Accessibility (commonly shortened to a11y)
        refers to the design of products, devices, services, or environments for people
        with disabilities. The concept of accessible design ensures both “direct access”(
        i.e. unassisted) and “indirect access” meaning compatibility with a person’s
        assistive technology (for example, computer screen readers). (https://en.wikipedia.
        org/wiki/Accessibility) of notices across core.
         - ![](https://secure.gravatar.com/avatar/6b6d1c4d29f1b149da0008917c70b019408d5af404a46bca853e4dd33546e1ed?
           s=32&d=mm&r=g)
         -  [Joost de Valk](https://profiles.wordpress.org/joostdevalk/)  9:51 am _on_
           November 17, 2023
         - When more work has been done on this, it would be good to also update the
           documentation at [https://developer.wordpress.org/reference/hooks/admin_notices/](https://developer.wordpress.org/reference/hooks/admin_notices/)
           to reference these functions.
 5.  ![](https://secure.gravatar.com/avatar/305d95f8b7d79d4ff0321b99a8f57b73a5bba7f5489e56e2f57a6552e0a92991?
     s=32&d=mm&r=g)
 6.   [Rhys Wynne](https://profiles.wordpress.org/rhyswynne/)  9:25 am _on_ October
     27, 2023
 7.  Very curious to see how this develops. I’ve been spinning my own up and they are…
     less than ideal.
 8.  ![](https://secure.gravatar.com/avatar/3a4eedfdaf403dbe8dabfd7ea20341c5ac3f3da5812c354894331c585bbd4e0a?
     s=32&d=mm&r=g)
 9.   [Hidekazu Ishikawa](https://profiles.wordpress.org/kurudrive/)  12:33 pm _on_
     November 3, 2023
 10. Isn’t the $paragraph_wrap parameter a boolean rather than an array?
 11.  * ![](https://secure.gravatar.com/avatar/737c2df3eecd59128718fa1f089e99f9463e664b51920f15bf781b2578015a2f?
        s=32&d=mm&r=g)
      *  [Colin Stewart](https://profiles.wordpress.org/costdev/)  7:34 pm _on_ November
        6, 2023
      * Nicely spotted, fixed!

Comments are closed.

# Post navigation

[← Updates to user-interface components in WordPress 6.4](https://make.wordpress.org/core/2023/10/16/editor-components-updates-in-wordpress-6-4/)

[Changes to attachment pages →](https://make.wordpress.org/core/2023/10/16/changes-to-attachment-pages/)