Display Alert or Error Message on Admin Pages
You know those error messages you sometimes see at the top of WordPress admin pages? Sometimes they’re helpful, other times not so much. But, its really easy to add them to a theme or plugin. I’ve used them to prompt users to check a setting when the theme or plugin is first installed.
Call it from another function to produce an error message or alert based on user action. Leave it as-is for a constant reminder (such as late payment notices).
Add to functions.php file or plugin.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | function showMessage($message1) { echo '<div id="message" class="updated fade">'; echo "<p>$message1</p></div>"; } function showErrorMessage($message2) { echo '<div id="message" class="error">'; echo "<p><strong>$message2</strong></p></div>"; } function showAdminMessages() { // Red Message // showErrorMessage("", true); //Yellow Message // showMessage("", true); } add_action('admin_notices', 'showAdminMessages'); |