如何移出WordPress前端管理工具栏

显然,大多数的WordPress用户不喜欢看到网站前端的WordPress管理栏面板,当然也有很

如何移出WordPress前端管理工具栏

显然,大多数的WordPress用户不喜欢看到网站前端的WordPress管理栏面板,当然也有很多去除前端管理面板的方法,比如之前WPMEE在这篇文章中介绍过的方法:如何在管理工具栏添加自定义链接,其中就涉及到如何移出前端管理工具栏,然而,他们只是禁用了管理栏,使管理栏的display:none,并没有将其中的JS,CSS完全移出。这里我们将告诉大家如何完全的移出WordPress前端管理工具栏包括JS,CSS代码等。
将下面的代码放到你主题的functions.php中就可以完全移出WordPress前端管理工具栏:
// Disable Admin Bar
if (!function_exists(\’df_disable_admin_bar\’)) {
function df_disable_admin_bar() {
// for the admin page
remove_action(\’admin_footer\’, \’wp_admin_bar_render\’, 1000);
// for the front-end
remove_action(\’wp_footer\’, \’wp_admin_bar_render\’, 1000);
// css override for the admin page
function remove_admin_bar_style_backend() {
echo \'<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>\’;
}
add_filter(\’admin_head\’,\’remove_admin_bar_style_backend\’);
// css override for the frontend
function remove_admin_bar_style_frontend() {
echo \'<style type=\”text/css\” media=\”screen\”>
html { margin-top: 0px !important; }
* html body { margin-top: 0px !important; }
</style>\’;
}
add_filter(\’wp_head\’,\’remove_admin_bar_style_frontend\’, 99);
}
}
add_action(\’init\’,\’df_disable_admin_bar\’);
好了,刷新下网页,看看管理面板使用的CSS已经JS是不是都没有了?
参考资料:http://www.trickspanda.com/2014/01/remove-wordpress-admin-bar/

作者: liuzhihao

为您推荐

返回顶部