How7o
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Reading: How to Show Custom Notifications in the WordPress Dashboard
Share
Subscribe Now
How7oHow7o
Font ResizerAa
  • Marketing
  • OS
  • Features
  • Guide
  • Complaint
  • Advertise
Search
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.
How7o > Blog > Web Development > How to Show Custom Notifications in the WordPress Dashboard
Web Development

How to Show Custom Notifications in the WordPress Dashboard

how7o
By how7o
Last updated: May 10, 2026
6 Min Read
WordPress admin notice — four notice types shown at the top of the admin area
SHARE

A wordpress admin notice — the coloured banner across the top of admin pages — is one hook (admin_notices) and a <div> with the right class. Four message types (info, success, warning, error) pick the colour, and is-dismissible adds the X button. This guide covers the minimal snippet, scoping it to specific screens, safe escaping, and the “show once and remember” pattern.

Contents
  • TL;DR
  • The four notice types
  • Scoping to specific screens
  • Scoping to specific roles
  • Show once per user
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-04-23 on WordPress 6.5 and PHP 8.3. Originally published 2023-05-22, rewritten and updated 2026-04-23.

TL;DR

add_action( 'admin_notices', 'how7o_show_admin_notice' );

function how7o_show_admin_notice() {
    $type = 'info';  // info | success | warning | error
    printf(
        '<div class="notice notice-%s is-dismissible"><p>%s</p></div>',
        esc_attr( $type ),
        esc_html__( 'Hello World!', 'how7o' )
    );
}

The four notice types

<div class="notice notice-info is-dismissible"><p>Blue — purely informational</p></div>
<div class="notice notice-success is-dismissible"><p>Green — action completed</p></div>
<div class="notice notice-warning is-dismissible"><p>Yellow — attention needed</p></div>
<div class="notice notice-error is-dismissible"><p>Red — something failed</p></div>

The class combinations are:

  • notice notice-info — informational (blue).
  • notice notice-success — success (green).
  • notice notice-warning — warning (yellow).
  • notice notice-error — error (red).
  • is-dismissible — adds the “×” close button. Omit for permanent notices.
wordpress admin notice — four notice types and the admin_notices hook

Scoping to specific screens

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

    // Only on the "All Posts" screen
    if ( ! $screen || $screen->id !== 'edit-post' ) {
        return;
    }

    echo '<div class="notice notice-info is-dismissible"><p>Heads up — new editor features rolling out.</p></div>';
} );

Without a scope check the notice renders on every admin page — noisy and quickly ignored. Common $screen->id values: dashboard, edit-post, edit-page, upload, options-general, plugins, themes. Print get_current_screen() once to discover the ID of wherever you want the notice.

Scoping to specific roles

add_action( 'admin_notices', function () {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;  // admins only
    }

    echo '<div class="notice notice-warning"><p>Backup ran 9 days ago — due for a refresh.</p></div>';
} );

A notice for admins only shouldn’t appear for editors or authors. current_user_can('manage_options') is the typical admin capability check; swap for edit_posts or a custom capability when the audience is broader.

Show once per user

add_action( 'admin_notices', function () {
    $user_id  = get_current_user_id();
    $meta_key = 'how7o_seen_welcome_notice';

    if ( get_user_meta( $user_id, $meta_key, true ) ) {
        return;
    }

    echo '<div class="notice notice-info is-dismissible"><p>Welcome to the new dashboard!</p></div>';

    update_user_meta( $user_id, $meta_key, 1 );
} );

Stores a user-meta flag once the notice renders. Subsequent visits see the flag and skip the notice. For a proper “Dismiss permanently” button (the X cleared but on reload it’s back), wire a JS handler to an admin-ajax endpoint that updates the user meta when clicked.

Frequently asked questions

What’s the minimal wordpress admin notice snippet?

Hook admin_notices, echo a <div class="notice notice-{type} is-dismissible"><p>Message</p></div>. {type} is one of info, success, warning, error — WordPress styles each with the usual blue/green/yellow/red accent. is-dismissible adds the X-to-close button.

When should I use network_admin_notices instead?

On WordPress Multisite, admin_notices fires on the per-site admin; network_admin_notices fires on the Network Admin screens (/wp-admin/network/). If your notice applies to the network owner (a license expiring, a network-wide update), use the network hook. For per-site notices, stick with admin_notices.

How do I show the notice on only specific admin pages?

Check get_current_screen() inside the callback: $screen = get_current_screen(); if ($screen->id === 'edit-post') { echo '<div ...'; }. The id property tells you which screen the admin is on (dashboard, edit-post, options-general, etc.). Without a scope check the notice appears on every admin page.

Should I escape the message?

Yes — use esc_html() for plain text, wp_kses_post() for a message that needs a limited set of HTML tags. echo '<p>Hello</p>' with user-generated text interpolated raw is an XSS vulnerability; echo '<p>' . esc_html($message) . '</p>' is safe. The class attribute (notice-{type}) also needs esc_attr() if $type comes from untrusted input.

How do I make the notice disappear after one view?

Store a user meta flag after showing it and check the flag before echoing: if (!get_user_meta($user_id, 'seen_notice_x', true)) { echo '<div ...'; update_user_meta($user_id, 'seen_notice_x', 1); }. For the “Dismiss permanently” button, wire an admin_enqueue_scripts-loaded JS that calls an AJAX handler to set the meta on click.

Related guides

  • How to Display Different Menus to Logged-In Users in WordPress — another UI swap, user-state driven.
  • How to Check If a User Is Logged In in WordPress — capability checks in detail.
  • How to Schedule a Cron Job in WordPress Without a Plugin — pair a cron with an admin notice for operational output.
  • How to Disable Revisions and Autosave in WordPress — other admin-area customizations.

References

WordPress developer reference for admin_notices and the Notices UI: developer.wordpress.org/reference/hooks/admin_notices.

TAGGED:configurationphpwordpress

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article WordPress system cron — DISABLE_WP_CRON + system crontab hitting wp-cron.php How to Set Up a System-Based Cron Job in WordPress
Next Article WooCommerce My Account login form hooks — five positions for injecting content How to Add a Link or Button After the Login Form in WooCommerce
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow

Subscribe Now

Subscribe to our newsletter to get our newest articles instantly!
Most Popular
Display PHP errors — ini_set + php.ini configuration
How to Display PHP Errors
May 10, 2026
PHP convert string to uppercase — strtoupper and mb_strtoupper
How to Convert a String to Uppercase in PHP
May 10, 2026
PHP string to float conversion with cast, regex cleanup, NumberFormatter
How to Convert a String to Float in PHP
May 10, 2026
PHP merge arrays without duplicates — union operator and array_unique
How to Combine Two Arrays Without Duplicates in PHP
May 10, 2026
PHP delete array element — unset, array_splice, array_filter, array_search
How to Delete an Element from a PHP Array
May 10, 2026

You Might Also Like

Create custom exception class in Laravel (Artisan command + secure error handling)
Web Development

How to Create a Custom Exception Class in Laravel (With Clean JSON Responses)

6 Min Read
WordPress posts by date range — date_query with after/before/inclusive
Web Development

How to Get Posts by Date Range in WordPress

7 Min Read
Find prime numbers in JavaScript thumbnail
Web Development

How to Find Prime Numbers in JavaScript (1 to 100) — Fast & Simple Methods

5 Min Read
WooCommerce remove checkout fields — woocommerce_checkout_fields filter unsetting fields
Web Development

How to Remove Checkout Fields in WooCommerce

6 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Latest News

  • SEO Audit Tool
  • Client ReferralsNew
  • Execution of SEO
  • Reporting Tool

Resouce

  • Google Search Console
  • Google Keyword Planner
  • Google OptimiseHot
  • SEO Spider

Get the Top 10 in Search!

Looking for a trustworthy service to optimize the company website?
Request a Quote
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?