Hide Front-End Admin Bar Including 32 px Spacing

I have a custom template and I inserted the following snippet to get rid of the admin bar for the page:

function hide_admin_bar(){ return false; }
add_filter( 'show_admin_bar', 'hide_admin_bar' );

The problem is this still leaves a blank white empty bar at the top of the page with a height of 32px. Looking at core, I see this function but there is no way to disable it. I also tried overriding html { margin-top: 0 !important; } in my theme stylesheet to no avail since this is output on the page directly.

function _admin_bar_bump_cb() { ?>
<style type="text/css" media="screen">
    html { margin-top: 32px !important; }
    * html body { margin-top: 32px !important; }
    @media screen and ( max-width: 782px ) {
        html { margin-top: 46px !important; }
        * html body { margin-top: 46px !important; }
    }
</style>

Does anyone have a clean way to completely remove the admin bar from the top of a specific template page (plus the white space)?

6 Answers
6

You can set the display status with show_admin_bar function

<?php show_admin_bar( false ); ?>

Leave a Comment