Halloween Sale 15% off Ends in See the plans
PHP

Auto-Hide the Admin Bar on the Front End

Slides the admin bar out of view on the front end and brings it back when you move the mouse to the top edge of the screen.

Don’t have WPIDE yet? Install it on your site

Code

add_action( 'wp_head', function () {
    if ( ! is_admin_bar_showing() ) {
        return;
    }
    ?>
    <style id="wpide-admin-bar-autohide">
        @media (hover: hover) and (min-width: 783px) {
            html { margin-top: 0 !important; }
            #wpadminbar { transform: translateY(calc(-100% + 5px)); transition: transform .2s ease .3s; opacity: .95; }
            #wpadminbar:hover, #wpadminbar:focus-within { transform: none; transition-delay: 0s; }
        }
    </style>
    <?php
}, 100 );

Notes

Touch screens and narrow windows keep the normal admin bar, because there is no hover there.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.