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
1 Answer
Reset to default 0You 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
版权声明:本文标题:pages - Remove 3rd party plugin notices from within own plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736298671a1930274.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论