How to Display a Custom Message in WordPress Admin Panel

Add Tool

How To Add A Custom Message in WordPress Admin Panel


How To Add A Custom Message in WordPress Admin Panel

Some time you want to update your WordPress theme or plugins and other things. When you do, it may be made some problem of your user. So you should inform your user or guest by adding some custom message in WordPress admin panel that something important needs doing, perhaps due to an upgrade. E.g. you need the user to update a setting. Here I have present a WordPress hook which will display a custom message to admins.

Add Custom message in WordPress admin panel

To display the urgent or custom message in WordPress admin panel add the below snippet into your WordPress theme’s functions.php file. This simple piece of code will display urgent message in WordPress Admin Panel like the below image.

wordpress admin panel

function showMessage($message, $errormsg = false){
    if ($errormsg) {
        echo '<div id="message" class="error">';
    } else {
        echo '<div id="message" class="updated fade">';
    }

    echo "<p><strong>$message</strong></p></div>";
}  

function showAdminMessages() {
    showMessage("Dear Sir, You need to upgrade your database as soon as possible...", true);

    if (user_can('manage_options')) {
       showMessage("Hello admins!");
    }
}

add_action('admin_notices', 'showAdminMessages');

Here change

showMessage("Dear Sir, You need to upgrade your database as soon as possible...", true);

To

showMessage("Your own custom message for your user", true);

Tags: wordpress admin panel, admin panel wordpress, custom wordpress admin panel, wordpress custom admin panel, Custom message in WordPress admin panel
Payza

About Masum Billah

How To Add A Custom Message in WordPress Admin Panel Hi I am Md. Masum Billah Contributor of this website. I always like to share various things with other. In this website I am sharing web design related tips and tricks, necessary web development tools, source codes for beginner and advance web developer.


SIGN UP TO GET UPDATE TO YOUR INBOX




Discuss about: How to Display a Custom Message in WordPress Admin Panel


adf.ly