wp_admin_notice( string $message, array $args = array() )

Outputs an admin notice.

Parameters

$messagestringrequired
The message to output.
$argsarrayoptional
An array of arguments for the admin notice.
  • type string
    Optional. The type of admin notice.
    For example, 'error', 'success', 'warning', 'info'.
    Default empty string.
  • dismissible bool
    Optional. Whether the admin notice is dismissible. Default false.
  • id string
    Optional. The value of the admin notice’s ID attribute. Default empty string.
  • additional_classes string[]
    Optional. A string array of class names.
  • attributes string[]
    Optional. Additional attributes for the notice div.
  • paragraph_wrap bool
    Optional. Whether to wrap the message in paragraph tags. Default true.

Default:array()

Source

function wp_admin_notice( $message, $args = array() ) {
	/**
	 * Fires before an admin notice is output.
	 *
	 * @since 6.4.0
	 *
	 * @param string $message The message for the admin notice.
	 * @param array  $args    The arguments for the admin notice.
	 */
	do_action( 'wp_admin_notice', $message, $args );

	echo wp_kses_post( wp_get_admin_notice( $message, $args ) );
}

Hooks

do_action( ‘wp_admin_notice’, string $message, array $args )

Fires before an admin notice is output.

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

  1. Skip to note 4 content

    In the plugin php file, using wp_admin_notice() throws an error, I just wrap it in the add_action hook

    add_action( 'admin_notices', function () {
    	wp_admin_notice(
    		__( 'Your success message here.', 'your-text-domain' ),
    		array(
    			'id'                 => 'message',
    			'additional_classes' => array( 'updated' ),
    			'dismissible'        => true,
    		)
    	);
    } );

You must log in before being able to contribute a note or feedback.