The admin_notices hook is a WordPress action hook that is triggered on the administration screen every time there is an error, warning, or any kind of notification that is meant for the user. This hook is useful in situations where you need to display a message to the user in the WordPress admin area.
The admin_notices hook is a popular hook that is commonly used by plugin developers to display notifications to the user, such as when a plugin has been successfully installed, updated, or when there is an error that needs to be addressed. The hook is also used by WordPress itself to display notifications to the user, such as when a new version of WordPress is available.
Here is an example usage code:
function my_plugin_admin_notice() {
?>
<div class="notice notice-success is-dismissible">
<p><?php _e( 'My Plugin has been successfully installed!', 'my-plugin-textdomain' ); ?></p>
</div>
<?php
}
add_action( 'admin_notices', 'my_plugin_admin_notice' );
In the code above, we are creating a function called my_plugin_admin_notice
that will display a success message to the user when the plugin is successfully installed. We are then using the add_action
function to attach this function to the admin_notices
hook so that it will be triggered whenever there is a notification that needs to be displayed.
Overall, the admin_notices hook is an essential hook for any WordPress developer looking to create user-friendly plugins that can communicate important information to the user in the WordPress admin area.
WordPress snippets using the admin_notices hook
-
Elementor plugin
-
Create a plugin to scan local.ch, and extract site data including: email, website, metaname generator, wordpress version
-
How to Enable Milestone Sales Alerts in Easy Digital Downloads
-
How to Display the Total Number of PDF Files in Your WordPress Media Library
-
How to Display the Total Number of Registered Users in WordPress
-
How to Display a List of Allowed Mime Types using get_allowed_mime_types in WordPress
-
How to Check the PHP Version in WordPress
-
How to Identify the WordPress Theme Used by Any Website
-
How to Display Update Notification for Admins in WordPress
-
How to Display the Total Number of Spam Comments in WordPress