Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

admin_notices

Prints notices at the top of admin screens. Use it for reminders, warnings or confirmation messages in the dashboard.

  • Type Action
  • From WordPress
  • Since 3.1.0
  • Fired in wp-admin/admin-header.php

When it fires

admin_notices runs on admin screens (each site's admin in multisite) at the end of the admin header, before the screen's own content, so notices appear near the top of the page.

The network admin uses network_admin_notices instead, and all_admin_notices fires on every kind of admin screen.

Parameters

None. Your callback takes no arguments.

Example: Show a reminder on the Dashboard

PHP
add_action( 'admin_notices', function () {
	$screen = get_current_screen();
	if ( ! $screen || 'dashboard' !== $screen->id || ! current_user_can( 'manage_options' ) ) {
		return;
	}
	wp_admin_notice(
		__( 'Reminder: the site goes into maintenance on Friday at 18:00.', 'my-snippets' ),
		array(
			'type'        => 'info',
			'dismissible' => true,
		)
	);
} );

Good to know

  • wp_admin_notice(), added in WordPress 6.4, builds the right markup for you. 'dismissible' only hides the notice until the next page load.
  • Check get_current_screen() and a capability so the notice only shows where, and to whom, it matters.
  • This hook fires on every admin screen, so avoid slow checks here.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.