問題描述
登入後,管理欄將以下內容新增到我的頁面<head> 部分中:
<style media="screen" type="text/css">
html { margin-top: 28px !important; }
* html body { margin-top: 28px !important; }
</style>
現在,我可以透過停用管理欄來刪除它
/* Disable the Admin Bar. */
add_filter( 'show_admin_bar', '__return_false' );
或完全刪除它
/* Remove admin bar */
remove_action('init', 'wp_admin_bar_init');
我想在 admin 介面中保留管理員欄,只能從前端刪除 CSS 。
我已經使用 CSS 重置,我設定了 margin: 0px,但 admin-bar 樣式覆蓋了這一點。
那麼如何從前端刪除樣式?
PS 。我知道我可以停用每個使用者的管理員欄,但這不是我想要的。
最佳解決方案
function hide_admin_bar_from_front_end(){
if (is_blog_admin()) {
return true;
}
return false;
}
add_filter( 'show_admin_bar', 'hide_admin_bar_from_front_end' );
次佳解決方案
f 要從頁面中刪除管理欄 (工具欄) 和 bump CSS,請使用:
function wpse_99333_hide_admin_bar_from_front_end(){
if ( is_blog_admin() ) {
return true;
}
remove_action( 'wp_head', '_admin_bar_bump_cb' );
return false;
}
add_filter( 'show_admin_bar', 'wpse_99333_hide_admin_bar_from_front_end' );
_admin_bar_bump_cb 功能是插入 CSS(位於 wp-includes /admin-bar.php)
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。