Remove WordPress Admin Bar CSS
A version or two back, WordPress decided to add a toolbar for logged in users on the display side that's about the site's theme. I get why they did it but it's an annoyance to me -- I don't care to see it. To accomplish this task, WordPress injects the following into every page:
<style type="text/css" media="print">#wpadminbar { display:none; }</style>
<style type="text/css" media="screen">
html { margin-top: 32px !important; }
* html body { margin-top: 32px !important; }
@media screen and ( max-width: 782px ) {
html { margin-top: 46px !important; }
* html body { margin-top: 46px !important; }
}
</style>
Bleh. You can remove this CSS and the admin bar using the following code which should be placed with your functions.php
file:
add_action('get_header', 'remove_admin_login_header');
function remove_admin_login_header() {
remove_action('wp_head', '_admin_bar_bump_cb');
}
Use it. You're welcome.
I love almost every part of being a tech blogger: learning, preaching, bantering, researching. The one part about blogging that I absolutely loathe: dealing with SPAM comments. For the past two years, my blog has registered 8,000+ SPAM comments per day. PER DAY. Bloating my database...
You've probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don't see what makes them so special. Can't you just use a callback? What's the big deal? In this article, we'll...
I recently received an email from a reader who was really impressed with Block Clickable, a jQuery script that took the link within a list item and made the entire list item clickable. I thought it was a neat script so I...
One excellent way to add dynamism to any website is to implement a slideshow featuring images or sliding content. Of course there are numerous slideshow plugins available but many of them can be overkill if you want to do simple slideshow without controls or events.
useful, but why you don’t just uncheck the “Show Toolbar when viewing site” option in your User Profile?
With this you can apply a “blanket” implementation for all users — you wouldn’t need to tell them to do so.
Right, I’m agree.
Thank you David
Perfect!
So I always remember: https://gist.github.com/kjantzer/e3f3524b22511f882497
You can also do this with
show_admin_bar(false);
in functions.php… You’re welcome ;)the original tip didn’t work but this one did, thanks!
The easiest and most recommendable way would be this:
You should always use filters. And this is the most accurate one.
This doesn’t remove the css. It removes the admin bar.
Thanks Pascal Birchler!
I could have used this snippet a while back. Thanks!
Not everyone using WordPress understands PHP, so some people might feel more comfortable using CSS.
This css turns a problem for the higher levels of editor, admin profile, that needs the admin bar on the top.
Thank you so much! The css
html{margin-top: 0 !important}
didn’t work, but your function works perfectly.I have custom home page and blog on other page. I had
32px
margin-top in html only on home page, but this works perfectly :)from the class-wp-admin-bar.php comments:
To remove the default padding styles from WordPress for the Toolbar, use the following code:
Thank you! This was just what I was looking to get rid. :)
I prefer this approach, Thanks TJ.
I’m glad I’m not the only one who goes nuts from this toolbar – it interferes with design, it’s just mind boggling how did they come up with it… I prefer your solution precisely because it removes it from all users at once. Thanks!
I know this topic is old but
add_action
thingy gets me an error… is it because I’m working in localhost?Thanks! worked like a charm :) was looking for the source of this code for hours!
Thanks for this. This issue came up for me with a menu that slides in from the right side. Every time I opened the menu that
32px
would be added to the top and create a white space. This fixed it instantly.Works!
I wanted to KEEP the admin bar, but it conflicted with my off-screen navigation in my theme, so the removal of CSS ONLY was needed since it was impossible for me to override the css specificity (HTML
{ margin-top:32px !important; }
)Several comments above is for REMOVING admin bar which was not the objective of the post.
I hate the margin-top issue it would break my layout especially if I was using Bootstrap navba-fixed-top. Here is a simple css solution if you want to keep the WP admin bar and avoid overlapping. Please note that the height of the WP admin bar is taller when in mobile view.
This is perfect JP! Thank you!
Thank you for this function! That whitespace was driving me crazy!
I not only see the white space still (after using the fix above) but I can also see a sad face there too, not when logged into admin but when logged out anyone know about this?? The fix only fixed when logged in but when logged out, its back!
Love this solution, when working with absolute elements (sidebar that slides out) this is needed.
Works flawlessly. You can even check if user is loggged in at this point (get_header).
Thanks a lot.
I really wish wp devs would allow the output to be filtered, especially css rules that are cancelled out with an asterisk and others that forced !important.
I took another approach. This hides the admin bar except the 32px wp icon in the top-left corner and on hover slides the full admin bar down into view leaving the entire site unobstructed except the top-left 32px.
1 – Set wp icon fixed w/ same menu bar bg-color + fix 2nd child position:
2 – pull entire bar up (except wp icon), set nice transition on hover:
3 – use negative margin on body element bring content to top of viewport:
4 – Set media queries for 32/46px transition: