hooks - Display $pagenow error notice on all admin pages

I need to show my client error message on all admin pages.I have the following code, that adds a custom notice only on t

I need to show my client error message on all admin pages.

I have the following code, that adds a custom notice only on the admin dashboard page:

add_action('admin_bar_menu', 'custom_toolbar_link2', 999);

function general_admin_notice(){
    global $pagenow;
    if ( $pagenow == 'index.php' ) {
         echo '<div class="notice notice-error">
             <h3>My custom text</h3>
         </div>';
    }
}

Is there any way to display this notice on all admin pages?

I need to show my client error message on all admin pages.

I have the following code, that adds a custom notice only on the admin dashboard page:

add_action('admin_bar_menu', 'custom_toolbar_link2', 999);

function general_admin_notice(){
    global $pagenow;
    if ( $pagenow == 'index.php' ) {
         echo '<div class="notice notice-error">
             <h3>My custom text</h3>
         </div>';
    }
}

Is there any way to display this notice on all admin pages?

Share Improve this question edited Mar 22, 2019 at 14:32 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Mar 22, 2019 at 14:17 JurajJuraj 1542 silver badges11 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1
function my_admin_notice() {

    /*
     * The class of admin notice should be "notice" plus any one of
     * -"notice-error",
     * -"notice-warning",
     * -"notice-success"
     * -"notice-info".
     * Optionally use "is-dismissible" to apply a closing icon.
     */

    echo '<div class="notice notice-info"><p>Custom notice text</p></div>';

}

add_action( 'admin_notices', 'my_admin_notice' );

The only thing is, these notices does not show up on New Post, Edit Post and similar where Gutenberg reins. There must be the solution, but I can't find it right now.

Sure there is a method to do this. You just need to attach your function to a different hook, admin_notices. You can even add classes that will turn into coloured bars, telling the user how important the message is.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745665452a4639096.html

相关推荐

  • hooks - Display $pagenow error notice on all admin pages

    I need to show my client error message on all admin pages.I have the following code, that adds a custom notice only on t

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信