TL;DR
- Use
admin_noticesto output messages. - Make notices dismissible with the
is-dismissibleclass. - Restrict notices with
current_user_canto avoid exposing sensitive info.
What Are Admin Notices?
Admin notices are banner messages displayed in the WordPress dashboard. They’re used for updates, success confirmations, error alerts, and onboarding guidance. Proper notices improve UX without forcing custom UI pages.
When to Use Admin Notices
Use notices for short, time-sensitive messages that belong in the admin UI: a setting was saved, a background task finished, a missing dependency needs action, or an update requires attention. Avoid using notices for long documentation, marketing, or upsells. Think of admin notices as high-intent, low-friction confirmations that help users move forward without interrupting their workflow.
If the message is persistent and complex, prefer a dedicated settings screen or a dashboard widget. For one-off guidance after activation, show a notice only once and then hide it permanently for that user.
Use the Right Hook
Output notices inside admin_notices or all_admin_notices. This keeps notices in the correct region and prevents layout issues.
Target the Right Screen
Notices should appear only where they are relevant. Check the current screen ID and return early for other pages. This reduces noise and keeps performance tight.
function fyrepress_notice_on_settings_screen() {
$screen = get_current_screen();
if (!$screen || $screen->id !== 'settings_page_fyrepress') {
return;
}
echo '<div class="notice notice-info is-dismissible">';
echo '<p>Remember to save your changes.</p>';
echo '</div>';
}
add_action('admin_notices', 'fyrepress_notice_on_settings_screen');
For post editor pages, check post.php or post-new.php and match the post type as needed.
Basic Notice Example
This example shows a dismissible success notice, visible only to admins.
function fyrepress_admin_notice() {
if (!current_user_can('manage_options')) {
return;
}
echo '';
echo 'Settings saved successfully.
';
echo '';
}
add_action('admin_notices', 'fyrepress_admin_notice');
FyrePress tool: Use the WP Admin Notice Generator to build notices with the right classes.
Notice Types & Classes
Core notice types include notice-success, notice-warning, notice-error, and notice-info. Always include the base notice class.
Use notice-success for saved settings and completed actions, notice-warning for reversible issues, and notice-error when the user must take immediate action. Reserve notice-info for neutral guidance or status updates.
Write Clear, Actionable Copy
Good admin notice copy is short, specific, and tells the user what to do next. Start with the outcome and add a clear action if required. Avoid generic phrasing like “Something went wrong.” Instead, identify the context: “Backup failed. Check your storage credentials.”
If a notice needs a button, include a simple link styled as a standard WordPress button. Keep the notice body under two sentences, and don’t stack multiple actions in the same message.
Persist Dismissal (User Meta)
If a notice should stay dismissed, store a flag in user meta. Check the flag before rendering the notice, and update it when the user dismisses it. This keeps repeat notifications from becoming noise.
function fyrepress_dismissible_notice() {
if (!current_user_can('manage_options')) {
return;
}
$user_id = get_current_user_id();
if (get_user_meta($user_id, 'fyrepress_notice_dismissed', true)) {
return;
}
echo '<div class="notice notice-info is-dismissible" data-fp-notice="welcome">';
echo '<p>Welcome! Configure settings to get started.</p>';
echo '</div>';
}
add_action('admin_notices', 'fyrepress_dismissible_notice');
function fyrepress_notice_dismiss() {
if (!current_user_can('manage_options')) {
wp_send_json_error();
}
update_user_meta(get_current_user_id(), 'fyrepress_notice_dismissed', 1);
wp_send_json_success();
}
add_action('wp_ajax_fyrepress_notice_dismiss', 'fyrepress_notice_dismiss');
Trigger the AJAX action when the user clicks the dismiss button, or detect the dismissal with a small script that listens for the standard WordPress dismiss event.
Multisite & Network Admin
In multisite, show network-level messages in the Network Admin using network_admin_notices. For site-level dashboards, keep notices on admin_notices. Use is_network_admin() to gate behavior when a plugin supports both contexts.
Performance & Noise Control
Avoid expensive queries inside the notice hook because it runs on every admin page load. Cache heavy checks with transients or store results in options. Also, reduce notice clutter by showing only one critical message at a time and suppressing lower-priority notices until the main issue is resolved.
Security & Sanitization
Escape all dynamic content with esc_html or wp_kses_post. Do not output raw user input inside notices. Validate any query parameters that trigger notices, and use nonces if the notice links to a sensitive action.
Accessibility & Localization
Keep notices readable for all users. Use plain language, avoid color-only meaning, and keep sentences short. If you add icons, include visually hidden text for screen readers.
Wrap notice strings in translation functions like __() or esc_html__(). This enables localization and keeps your admin messages consistent across different languages.
Frequently Asked Questions
How do I make a WordPress admin notice dismissible?
Add the is-dismissible class to the notice wrapper.
Where should I hook admin notices?
Use admin_notices or all_admin_notices.
How do I show notices only on a specific admin screen?
Check get_current_screen() and return early for unrelated pages.
How do I show notices only to specific roles?
Wrap output in current_user_can capability checks.
What hook should I use in multisite network admin?
Use network_admin_notices for the Network Admin screens.
Can I persist a notice after dismissal?
Yes. Store a user meta flag and suppress the notice after it’s dismissed.
Key Takeaways
- Use correct hooks and classes to render notices reliably.
- Target screens, roles, and networks to reduce noise.
- Gate notices with capabilities and sanitize output.
- Persist dismissal and keep notice logic lightweight.
Generate a notice instantly
Use the WP Admin Notice Generator to create clean, dismissible notices.