Body class admin-bar missing on some pages

The body class admin-bar has apparently not been implemented consistently. For style purposes, however, I need this class because parts of my left bar are obscured by the admin bar.

Here is the code I currently use to have the body class admin-bar available everywhere.

add_filter( 'body_class', 'add_body_class' , 11);
function add_body_class ( $classes )
{
	if (is_admin_bar_showing())
	{
		$classes[] = "admin-bar";
	}
	return $classes;
}

The css:

body.admin-bar .x-bar-left,
body.admin-bar .x-bar-right
{
	top: 32px;
}

Hi @Regnalf,

I have tried to replicate the issue but didn’t find that in my local environment. Can you please share the URL where you are having such an issue?

Thanks

I’ve gave you a Testuser with the corresponding role that have the left nav bar, wehre you can see the issue. I also deactivated my script that you can see the issue. More details in secure note.

Hi @Regnalf,

The admin-bar class is added by WordPress itself so this wouldn’t be a problem with Pro. We don’t remove it at any point.

Thank you! Well, then it is a thing of WordPress and I hope I can help others who have the same problem.
WordPress also seems to only add it to post pages.

Anyway, the code from me seems to work.

Hi @Regnalf,

Thanks for sharing your idea, we really appreciate it!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.