Hello Everyone, I you want to add a custom admin notice on wordpress website then this post will be beneficial for you.
You can add the custom admin notice message on wordpress admin dashboard by using hooks of the wordpress. You just need to copy and paste the below code into your theme function.php file. And also if you want to display any admin notice by wordpress plugin in that case you can also given below code.
In order to display a notice for different purpose, you can use following classes:
- notice-error - will display the message with a white background and a red left border.
- notice-warning- will display the message with a white background and a yellow/orange left border.
- notice-success - will display the message with a white background and a green left border.
- notice-info - will display the message with a white background a blue left border.
To display any useful information
if(!function_exists('my_custom_admin_notice__success')) :
function my_custom_admin_notice__success()
{
$message = '<div class="notice notice-success is-dismissible">
<h2><a href="https://www.youtube.com/c/WPEXPERTSIN">Join us to learn wordpress classes</a>!</h2>
</div>'; echo $message; //print message
}
add_action( 'admin_notices', 'my_custom_admin_notice__success' ); endif;
To display any warning or error message
if(!function_exists('my_custom_admin_notice__error')) :
function my_custom_admin_notice__error() {
$class = 'notice notice-error';
$message = __( 'Opps! An error has occurred.', 'wp-experts.in' );
printf( '<div class="%1$s">%2$s</div>', esc_attr( $class ), esc_html( $message ) );
}
add_action( 'admin_notices', 'my_custom_admin_notice__error' );
endif;
Watch video to know how it works
[youtube https://www.youtube.com/embed/ETiI_gfK8XE]