Skip to content

Instantly share code, notes, and snippets.

@galbaras
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galbaras/d8c4c7c00a9fe58a39af to your computer and use it in GitHub Desktop.
Save galbaras/d8c4c7c00a9fe58a39af to your computer and use it in GitHub Desktop.
Toggling the display of the WordPress Admin Bar (wpadminbar)
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.
html.no-admin-bar {
margin-top: 0 !important;
}
<?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