Last active
August 29, 2015 14:13
-
-
Save galbaras/d8c4c7c00a9fe58a39af to your computer and use it in GitHub Desktop.
Toggling the display of the WordPress Admin Bar (wpadminbar)
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
The WordPress admin bar can sometimes get in the way of checking what a site looks like | |
while being logged in, so it's convenient to hide it occasionally. | |
To do this, we need a CSS class and some jQuery code, which toggles the admin bar display | |
when pressing Shift-A. | |
The CSS can be added to the theme's normal stylesheet. The PHP/jQuery code can be added | |
into footer.php or included within an action in functions.php. | |
* The code was adapted from the Bottom Admin Bar plugin. |
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
html.no-admin-bar { | |
margin-top: 0 !important; | |
} |
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 if ( is_user_logged_in() ) { ?> | |
// Toggle admin bar display with Shift-A | |
jQuery(document).ready(function($) { | |
$('body').keydown(function( event ) { | |
if ( event.shiftKey === true && event.which === 65 ) { | |
$('#wpadminbar').toggle(); | |
$('html').toggleClass('no-admin-bar'); | |
} | |
}); | |
}); | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment