I am trying to make a notice on wordpress dashboard only. but when i paste this code in function.php notice show on all the pages like, Post , Authors , Pages everywhere. I just want only show on main dashboard Page.
function sample_admin_notice__success() {
?>
<div class="notice notice-success is-dismissible">
<p><?php _e( 'Done!', 'sample-text-domain' ); ?></p>
</div>
<?php
}
add_action( 'admin_notices', 'sample_admin_notice__success' );
You can check for the current screen
function sample_admin_notice__success() {
?>
<div class="notice notice-success is-dismissible">
<p><?php _e( 'Done!', 'sample-text-domain' ); ?></p>
</div>
<?php
}
if (is_admin()) {
$screen = get_current_screen();
if ($screen -> id == "dashboard") {
add_action( 'admin_notices', 'sample_admin_notice__success' );
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.