admin管理员组

文章数量:1122846

I'm trying to build a plugin (complete novice) and on the landing page of my plugin I don't get the 3rd party plugin notices / banners but with all of my sub pages I do. How can I completely remove these notices / banners from all my plugin's pages..? The Mailchimp Banner for example is what I speak of.

Main Plugin Page:

Sub Page:

I'm trying to build a plugin (complete novice) and on the landing page of my plugin I don't get the 3rd party plugin notices / banners but with all of my sub pages I do. How can I completely remove these notices / banners from all my plugin's pages..? The Mailchimp Banner for example is what I speak of.

Main Plugin Page:

Sub Page:

Share Improve this question asked Aug 7, 2024 at 2:11 demo7updemo7up 1789 bronze badges 1
  • Why would you want to? Those notifications are for the site admin's benefit (unless they are Yoast notifications, in which case they are for the site admin's annoyance). – vancoder Commented Aug 7, 2024 at 16:13
Add a comment  | 

1 Answer 1

Reset to default 0

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 );

本文标签: pagesRemove 3rd party plugin notices from within own plugin