admin_notices

Home » Hooks » admin_notices

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.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.