I've created a sticky menu but its hidden behind the WordPress Toolbar when logged in. How do i move it below the toolbar when enabled and logged in?

I was looking for a conditional tag but couldn't find one for this. I guess there's a WordPress hook or filter that i could use.


I assume you mean on the admin bar on the front end, that show up for logged in users.

The body_class function inserts a class called admin-bar when that is present. The admin bar is 28px high. You should be able to use that body class to conditionally relocate your sticky menu.

| improve this answer | |
body.admin-bar div.sticky.fixed { margin-top: 28px; }
| improve this answer | |
  • Please explain your code rather than just post the code itself. – s_ha_dum Oct 11 '13 at 21:18

The best way to go about doing this is to simply move the admin bar to the bottom with this plugin. Its so simply, clean and less confusing. I use it for all my sticky menu sites.

LINK: http://wordpress.org/plugins/stick-admin-bar-to-bottom/

I know this doesnt "exactly" answer your questions buts its a great alternative.

| improve this answer | |

You want to add a conditional function to your functions.php file.

This works for me:

if ( is_admin_bar_showing() ) {     echo '<style type="text/css"> nav {margin-top: 32px;} </style>'; }

I checked in an incognito tab too. nav moves back to the top of the screen.

The only thing I haven't worked out how to do best is detecting viewport/nav size so that you can detect the size of either/or and then adjust the margin accordingly.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.