Fix the Admin Bar Covering Your WordPress Header

Quick Summary
- Print a logged class on the header wrapper with is_user_logged_in(), then add CSS margins under .logged to push the header down.
- Swap the example selectors for your own header elements; the toolbar is 32px tall on desktop and 46px at 782px or narrower.
- Users can hide the toolbar while logged in, so the admin-bar body class from body_class() is a more precise hook.
When you’re logged in, WordPress shows the admin bar across the top of your site. If your theme has a fixed or sticky header, the toolbar can cover part of it, even though the layout looks fine to visitors. One fix is to add a class to the header only for logged-in users and push the header down with CSS.
Step 1: add a class to the header
Open your theme’s header.php and add this inside the class attribute of the header’s wrapper div:
<?php if ( is_user_logged_in() ) {echo 'logged';} ?>is_user_logged_in() returns true for a logged-in user, so the word logged is printed as an extra class. The code prints no space before it, so leave a space after the class name that comes before it.
Step 2: offset the header with CSS
Now write CSS that only applies when the logged class is present:
/*WP LOGGED IN HEADER FIXING CSS*/
.logged .home-sticky.fixed {
margin-top: 20px;
}
.logged .row.h-area {
margin-top: 40px;
}.home-sticky.fixedand.row.h-areaare elements of the theme this was written for. Replace them with your own header selectors and adjust the margins until nothing is hidden. Theloggedclass has to be on an element that contains them.- For reference, the toolbar is 32px tall on desktop and 46px tall on screens 782px wide or narrower.
- Users can switch the toolbar off in their profile but are still logged in, so the offset would still apply. If your theme uses
body_class(), theadmin-barclass on the<body>tag is only added while the toolbar is actually showing, which makes it a more precise hook for the same CSS (see how WordPress builds and filters body classes).
Related articles
- highlighting the active page in your navigation menu: another header style built on a class WordPress adds

