This is probably a massively obvious code snippet, but one that its exclusion has annoyed me for a long time now.
The admin bar in wordpress, whilst helpful, it is a little intrusive on your layout, especially when using a number of absolutely position elements. When you have the admin bar enabled, it *kindly* adds 28px to the top of the page to allow room for it. As said, this can sometime knock out the alignment of your absolutely positioned elements.
In the past I’ve added a couple of lines to my css, to counteract the added margin:
html { margin-top: 0px !important;}
* html body { margin-top: 0px !important;}
However, this will then be present in the css, even when the user isn’t logged in.
So a better method is to use the is_user_logged_in() function – <a href=”http://codex.wordpress.org/Function_Reference/is_user_logged_in”>read more</a>.
I thought best to also put the code into the footer, out the way and also as it is later in the markup, it will have higher importance to that of the other code.
So here’s the code to pop in the footer:
<?php if ( is_user_logged_in() ) { ?>
<style type="text/css" media="screen">
html { margin-top: 0px !important; }
* html body { margin-top: 0px !important; }
</style>
<?php } ?>
And that’s it…
