How to fix Wordpress admin panel breaking 100% height

I am creating a website that is suitable for the screen using Wordpress.

When the site owner logs in, the admin panel appears, but adds the following style:

html{ margin-top: 28px !important; }

This will cause a vertical scrollbar to appear. Is there a way to fix this using only CSS?

Someone had a similar problem , but he received no response.

My corresponding html structure:

<html>
   <body>
       <div id="page">
       <div class="site-main" id="main"> 
               <div class="content-area" id="primary">

                   <div role="main" class="site-content" id="content">

                   </div><!-- #content .site-content -->

               </div><!-- #primary .content-area -->         
           </div><!-- #main .site-main -->
       </div><!-- #page -->

       <div id="wpadminbar">

       </div>

   </body>
</html>

And the corresponding CSS:

html, body, #page {
    width: 100%;
    height: 100%;
    min-width: 350px;
    margin: 0;
    padding: 0;
}
#main {
    height: 100%;
}
#primary {
    float: right;
    width: 100%;
    margin-left: -200px;
    height: 100%;
}
#content {
    margin-left: 250px;
    height: 100%;
}

For admin panel:

#wpadminbar {
  height: 28px;
  left: 0;
  min-width: 600px;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 99999;
}

I tried using (negative) fields and paddings, also setting the admin panel positionon absoluteinstead fixed, but no luck.

+4
3

wordpress/wp-includes/class-wp-admin-bar.php , . :

if ( current_theme_supports( 'admin-bar' ) ) {
  /**
   * To remove the default padding styles
   * from WordPress for the Toolbar,
   * use the following code:
   * add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) );
   */
  $admin_bar_args = get_theme_support( 'admin-bar' );
  $header_callback = $admin_bar_args[0]['callback'];
}

if ( empty($header_callback) )
  $header_callback = '_admin_bar_bump_cb';

add_action('wp_head', $header_callback);

wordpress/wp-includes/admin-bar.php _admin_bar_bump_cb:

/**
 * Default admin bar callback.
 *
 * @since 3.1.0
 */
function _admin_bar_bump_cb() { ?>
<style type="text/css" media="screen">
  html { margin-top: 28px !important; }
  * html body { margin-top: 28px !important; }
</style>
<?php
}
+3

php- ( , , ), :

add_filter('show_admin_bar', '__return_false');

: http://davidwalsh.name/hide-admin-bar-wordpress

+2

Try the following:

add_action('get_header', 'fix_adminbar');

function fix_adminbar()
{
    if (is_admin_bar_showing()) {
        remove_action('wp_head', '_admin_bar_bump_cb');
        add_action(
            'wp_head', function () {
            ob_start();
            _admin_bar_bump_cb();
            $code = ob_get_clean();
            $code = str_replace('margin', 'padding', $code);
            $code = preg_replace('/{/', '{ box-sizing: border-box;', $code, 1);
            echo $code;
        }
        );
    }
}'''
0
source

All Articles