Last active
August 25, 2025 17:55
-
-
Save mwender/0bf939d37c6cb4a0ee8c15fc4b3e15b7 to your computer and use it in GitHub Desktop.
[WP Admin Bar - Sneaky Slidedown] Hides the WP Admin Bar and adds a "sneaky" slidedown with delay. #WordPress #PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Sneaky Slide-Down WP Admin Bar (with hide delay) | |
| * | |
| * Hides the admin bar until the mouse moves into a small "trigger zone" at the top. | |
| * Slides down on hover, and auto-hides 500ms after the mouse leaves. | |
| */ | |
| add_action( 'wp_footer', function() { | |
| if ( is_user_logged_in() && is_admin_bar_showing() ) : ?> | |
| <style> | |
| #wpadminbar { | |
| top: -32px; | |
| transition: top 0.3s ease; | |
| } | |
| html { | |
| margin-top: 0 !important; | |
| } | |
| * html body { | |
| margin-top: 0 !important; | |
| } | |
| /* Trigger zone style */ | |
| #adminbar-trigger { | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| width: 100%; | |
| height: 5px; | |
| z-index: 99998; | |
| } | |
| </style> | |
| <div id="adminbar-trigger"></div> | |
| <script> | |
| (function() { | |
| const bar = document.getElementById('wpadminbar'); | |
| const trigger = document.getElementById('adminbar-trigger'); | |
| let hideTimeout; | |
| function showBar() { | |
| clearTimeout(hideTimeout); | |
| bar.style.top = '0'; | |
| } | |
| function hideBar() { | |
| hideTimeout = setTimeout(() => { | |
| bar.style.top = '-32px'; | |
| }, 1500); | |
| } | |
| if (bar && trigger) { | |
| trigger.addEventListener('mouseenter', showBar); | |
| bar.addEventListener('mouseenter', showBar); | |
| bar.addEventListener('mouseleave', hideBar); | |
| } | |
| })(); | |
| </script> | |
| <?php | |
| endif; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment