2017-08-28 144 views
0

在一个WordPress博客我想禁用管理员/登录的用户topbar。删除WordPress的管理吧CSS

add_action('get_header', 'remove_admin_login_header'); 
function remove_admin_login_header() { 
remove_action('wp_head', '_admin_bar_bump_cb'); 
} 
add_action('after_setup_theme', 'remove_admin_bar'); 
function remove_admin_bar() { 
show_admin_bar(false); 
} 

上面的代码删除管理栏,但它仍然打印下面的CSS,我需要将其删除,因为它是无用的。

<style type='text/css'>#wp-admin-bar-ai-toolbar-settings .ab-icon:before{content:'\f111';top:2px;color:rgba(240,245,250,.6)!important;}#wp-admin-bar-ai-toolbar-settings-default .ab-icon:before{top:0px;}#wp-admin-bar-ai-toolbar-settings .ab-icon.on:before{color:#00f200!important;}#wp-admin-bar-ai-toolbar-settings-default li,#wp-admin-bar-ai-toolbar-settings-default a,#wp-admin-bar-ai-toolbar-settings-default li:hover,#wp-admin-bar-ai-toolbar-settings-default a:hover{border:1px solid transparent;}#wp-admin-bar-ai-toolbar-blocks .ab-icon:before{content:'\f135';}#wp-admin-bar-ai-toolbar-positions .ab-icon:before{content:'\f207';}#wp-admin-bar-ai-toolbar-positions-default .ab-icon:before{content:'\f522';}#wp-admin-bar-ai-toolbar-tags .ab-icon:before{content:'\f475';}#wp-admin-bar-ai-toolbar-no-insertion .ab-icon:before{content:'\f214';}#wp-admin-bar-ai-toolbar-ad-blocking .ab-icon:before{content:'\f160';}#wp-admin-bar-ai-toolbar-processing .ab-icon:before{content:'\f464';}#wp-admin-bar-ai-toolbar-positions span.up-icon{padding-top:2px;}#wp-admin-bar-ai-toolbar-positions .up-icon:before{font:400 20px/1 dashicons;}</style> 

你会用什么PHP代码或过滤器来删除它?

注意:我想删除CSS输出,而不是隐藏div!

+0

你为什么关心?留在那里,它不会受伤。 –

+0

我已经设置了一些插件来隐藏我使用WordPress的事实,但这些行清楚地显示它是WordPress。为什么我应该向用户提供许多无用的代码行?我喜欢干净的代码。 – Monzio

+0

我想删除CSS输出,而不是隐藏div – Monzio

回答

0
if (!function_exists('disableAdminBar')) { 

     function disableAdminBar(){ 

     remove_action('admin_footer', 'wp_admin_bar_render', 1000); // for the admin page 
     remove_action('wp_footer', 'wp_admin_bar_render', 1000); // for the front end 

     function remove_admin_bar_style_backend() { // css override for the admin page 
      echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>'; 
     } 

     add_filter('admin_head','remove_admin_bar_style_backend'); 

     function remove_admin_bar_style_frontend() { // css override for the 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_filter('admin_head','remove_admin_bar_style_backend'); // Original version 
    add_action('init','disableAdminBar'); // New version 

//JUST PAST THIS function.php 
0

试试这个,删除内嵌的CSS。复制到你的functions.php

add_action('get_header', 'remove_admin_login_header'); 
function remove_admin_login_header() { 
    remove_action('wp_head', '_admin_bar_bump_cb'); 
}