You can achieve this by using in_admin_header
hook of WordPress. With the help of this you can remove the notices from the admin as per your need. Since you want to remove the notices from specific pages then you can add condition for these pages in a code so notices will be removed from only these pages.
You need to add this code to the functions.php
file of your theme, this will gives you screen id of the page.
function find_current_screen_id() {
$screen = get_current_screen();
error_log( 'Current Screen ID : ' . $screen->id );
}
add_action('admin_notices', 'find_current_screen_id');
These screen ids can be used in adding condition to remove notices from the pages.
function hide_notices_to_all_but_super_admin(){
// Here we are checking if the current user is a super admin.
if ( ! is_super_admin() ) {
// Here we are getting the current screen object.
$screen = get_current_screen();
// Here we are specifying the screen ID where we want to apply the condition.
// PLease replace 'your_page_id' with the actual screen ID of the page where you want to remove notices.
if ( $screen->id === 'your_page_id' ) {
remove_all_actions( 'user_admin_notices' );
remove_all_actions( 'admin_notices' );
}
}
}
add_action( 'in_admin_header', 'hide_notices_to_all_but_super_admin', 99 );