How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Show Custom Notifications in the WordPress Dashboard
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > 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.
[mc4wp_form]
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
Most Popular
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026
Tailscale mesh — peer-to-peer connections between devices, coordination server
How to Install Tailscale on Ubuntu (Zero-Config Mesh VPN for Self-Hosters)
May 24, 2026
Caddy server — automatic HTTPS, 3-line Caddyfile vs 25-line nginx config
How to Install Caddy Server on Ubuntu (Automatic HTTPS, Drop-in nginx Alternative)
May 24, 2026
Cloudflare Tunnel — outbound-only connection from server, no inbound port forward
How to Install Cloudflare Tunnel on Ubuntu (Expose Local Services, No Port Forwarding)
May 24, 2026
WireGuard encrypted tunnel between server and clients with lock icons
How to Set Up WireGuard VPN on Ubuntu (Server, Linux Client, and iOS)
May 24, 2026

You Might Also Like

Laravel run project from GitHub — git clone through artisan serve pipeline
Web Development

How to Run a Laravel Project from GitHub

8 Min Read
PHP convert string to uppercase — strtoupper and mb_strtoupper
Web Development

How to Convert a String to Uppercase in PHP

6 Min Read
Laravel run without .env file — env() fallback in config/app.php
Web Development

How to Run a Laravel Project Without a .env File

8 Min Read
Run a Node.js application from a Windows .bat file
OS

How to Run a Node.js Application from a Windows .bat File

5 Min Read
How7o

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

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?