Skip to content

WordPress – Create function for displaying admin notices

Here is a neat function you can call to display notices in the admin panel.

function display_admin_notice($class='updated', $message) {
    global $notice;
    $notice = '<div class="'.$class.'"> <p>'.$message.'</p></div>';
    add_action('admin_notices', function() {
        global $notice;
        echo $notice;

Change class to ‘error’ or ‘update-nag’ etc…

display_admin_notice('error', 'You cannot be serious!');

Ref –


10 years + experience in web development working with lots of different technology.

Published inPHPWordPress

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *