我们都知道,如果WordPress官方推送新版本的WordPress时,都会在WordPress后台顶部显示一条高亮的提醒信息,如下如所示:
下面,倡萌就来分享下,在WordPress后台顶部添加错误提醒信息或升级提醒信息 的方法,这里需要借助 admin_notices 挂钩 来实现。只需要在主题的 functions.php 中添加下面的代码样例即可:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | function showMessage($message, $errormsg = false) { if ($errormsg) { echo ' <div id="message" class="error">'; } else { echo ' <div id="message" class="updated fade">'; } echo " <strong>$message</strong> </div> "; } function showAdminMessages() { showMessage("Welcome to the new WordPress theme.", true); } add_action('admin_notices', 'showAdminMessages'); |
function showMessage($message, $errormsg = false) { if ($errormsg) { echo ' <div id="message" class="error">'; } else { echo ' <div id="message" class="updated fade">'; } echo " <strong>$message</strong> </div> "; } function showAdminMessages() { showMessage("Welcome to the new WordPress theme.", true); } add_action('admin_notices', 'showAdminMessages');
参考资料:http://www.paulund.co.uk/show-urgent-messages-in-wordpress-dashboard
该方法只是告诉你如何显示提醒信息,但是作为WordPress主题开发或插件开发者,你应该添加一些判断条件来决定什么时候显示提醒信息。下面是一个很好的例子:如何自动提醒WordPress主题使用者安装必要插件
本文如何在WordPress后台顶部添加错误提醒信息或升级提醒信息到此结束。如果爱里没有责任,爱就变得自私。如果爱里没有节制,爱就容易放纵。如果爱里没有平等,爱就变成一种施舍。如果爱里没有尊重,爱就变成一种专制。如果爱里没有喜乐,爱就不能成为真爱。如果爱不能光明正大,爱就是罪恶的化身。小编再次感谢大家对我们的支持!