删除WordPress管理栏的CSS

时间:2017-08-28 10:10:58

标签: php css wordpress

在WordPress博客中,我想禁用管理员/登录用户的顶部栏。

Create table #Source  (
id  int ,
gender  nvarchar(6) ,
Age tinyint)
go

insert into  #Source 
 select 1, 'Male' ,  51 
 union all select 2, 'Male' ,   42 
 union all select 4, 'Female' ,   52 
 union all select 5, 'Male' ,   45 
 union all select 6, 'Male' ,   25 
 union all select 7, 'Male' ,   31 
 union all select 8, 'NA' ,   24 

 declare @sql nvarchar(max) , @SelectList nvarchar(max) , @Pvt1 nvarchar(max) , @Pvt2 nvarchar(max)

 select @SelectList = 'id ,[Male] as  [gender_Mail] ,Female as  [gender_Female] , NA as [gender_NA] , ' , @Pvt1 = '' , @Pvt2 = ''
 select @SelectList = @SelectList + '['  + cast(age as varchar(3)) + '] as [age_'  + cast(age as varchar(3)) + '] , '  from #Source
 select @SelectList = SUBSTRING(@SelectList ,1, LEN(@SelectList)-1) 

 select @Pvt1 = ' [Male], [Female] , [NA]'   
 select @Pvt2       =  @Pvt2 +  '['  + cast(age as varchar(3))+ '] , '  from #Source
 select @Pvt2 = SUBSTRING(@Pvt2 ,1, LEN(@Pvt2)-1)

 select @sql = N'select '+@SelectList+ '
  from #Source  s 
  PIVOT
(
    count(gender)
    FOR gender IN ('+ @Pvt1+ ')
)AS pvt1 PIVOT
(
    count(age)
    FOR age IN (' + @Pvt2 + ')
)AS pvt2'

exec sp_executesql  @sql

上面的代码删除了管理栏,但它仍会打印以下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);
}

您将使用哪些PHP代码或过滤器将其删除?

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

2 个答案:

答案 0 :(得分: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  

答案 1 :(得分: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');
}