Add Custom Admin Notices in WordPress

To add an admin notice in WordPress, hook a function into admin_notices and print a div with the notice class. It’s the same mechanism core and plugins use for success messages, warnings and errors at the top of wp-admin screens.

Use it for reminders to your content team, configuration warnings in a plugin, or a confirmation after a custom action.

Add a Custom Admin Notice

Add this to your child theme’s functions.php or to a plugin. It shows a dismissible warning on the Posts list screen only.

add_action( 'admin_notices', function () {
    $screen = get_current_screen();

    if ( ! $screen || 'edit-post' !== $screen->id ) {
        return;
    }

    echo '<div class="notice notice-warning is-dismissible">';
    echo '<p>' . esc_html__( 'Remember to set a featured image before publishing.', 'your-textdomain' ) . '</p>';
    echo '</div>';
} );

Change the screen ID check and the message to fit your case. Remove the screen check entirely to show the notice on every admin page.

How It Works

WordPress fires admin_notices near the top of every regular admin screen, before the page content. Core JavaScript then moves notices so they sit right below the page title.

The CSS classes control how the notice looks:

  • notice is required on every notice.
  • notice-success (green), notice-error (red), notice-warning (yellow) or notice-info (blue) set the color of the left border.
  • is-dismissible adds a close button.

get_current_screen() returns the current screen object. Useful IDs include dashboard, edit-post (Posts list), post (post editor), upload, plugins and options-general.

The wp_admin_notice() Function (WordPress 6.4+)

Since WordPress 6.4, wp_admin_notice() builds the markup for you. This is the same notice as above, without hand-written HTML:

add_action( 'admin_notices', function () {
    $screen = get_current_screen();

    if ( ! $screen || 'edit-post' !== $screen->id ) {
        return;
    }

    wp_admin_notice(
        esc_html__( 'Remember to set a featured image before publishing.', 'your-textdomain' ),
        array(
            'type'        => 'warning',
            'dismissible' => true,
        )
    );
} );

The type argument takes success, error, warning or info and adds the matching notice- class. Other arguments are id, additional_classes, attributes and paragraph_wrap, which is true by default. Output passes through wp_kses_post(), so links and <strong> survive but scripts don’t.

If your plugin still supports versions older than 6.4, wrap the call in function_exists( 'wp_admin_notice' ) or keep the manual markup.

Why the Notice Doesn’t Show in the Block Editor

When the block editor is active, it hides the classic notice area, so anything printed on admin_notices doesn’t appear while editing a post. Use the editor’s JavaScript notices store instead:

wp.data.dispatch( 'core/notices' ).createNotice(
    'warning',
    'Remember to set a featured image before publishing.',
    { isDismissible: true }
);

Enqueue that script only on the editor screens, as shown in Enqueue Scripts Only for Specific Admin Pages, with wp-data and wp-notices as dependencies. For more on actions and filters, see WordPress hooks explained.

FAQs

Common questions about WordPress admin notices:

Why does my dismissible notice come back after reload?
is-dismissible only removes the notice from the page with JavaScript. To keep it hidden, save the dismissal yourself, for example in user meta via an AJAX request, and check that value before printing the notice.
How do I show a success message after saving a custom form?
Redirect back with a query argument such as &saved=1, then check for it inside your admin_notices callback and print a notice-success. Settings API forms that submit to options.php get a "Settings saved." notice automatically.
Why don't my add_settings_error() messages appear?
WordPress calls settings_errors() automatically only on pages under the Settings menu. On a top-level or other custom admin page, call settings_errors() yourself at the top of the page output.
How do I show a notice in the Network Admin on Multisite?
Network Admin screens fire network_admin_notices instead of admin_notices. Use all_admin_notices if the notice should appear in both.
Discussion
[  0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!