I am having an issue with the WordPress admin bar overlapping the Twitter Bootstrap (2.3.0
) nav bar. I have tried this fix:
body.admin-bar .navbar-fixed-top {
top: 28px;
}
.navbar .brand {
color: #000 !important;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.1), 0 0 30px
rgba(255, 255, 255, 0.125);
font-weight: bold !important;
}
.nav-container {
padding-left: 0;
padding-right: 0;
}
.nav-tabs, .nav-pills {
margin-top: -6px;
}
.dropdown-menu li>a:hover,.dropdown-menu li>a:focus,.dropdown-submenu:hover>a
{
color: #fff !important;
}
#inner-header {
width: 100%;
}
input,textarea,select,.uneditable-input {
margin-bottom: 0;
}
.navbar-form,.navbar-search {
margin: 0 0 9px;
}
.navbar-search {
padding-left: 0;
}
#s {
width: 100px;
}
but alas it is still posing an issue. I am wondering what fixes are available?
How to prevent the WordPress admin bar from overlapping with your Twitter Bootstrap navigation bar.
In response to: WordPress admin bar overlapping twitter bootstrap navigation
Asked by:
@TheWebs
If you are using Twitter Bootstrap with WordPress and have an issue with the WordPress admin bar overlapping with your navigation bar, you’re probably pretty frustrated with some of these answers. I looked for solutions everywhere before ultimately deciding to just down-shift to a lower gear and figure out a solution that does exactly what I need it to do.
So here is an answer that doesn’t hide the WordPress admin bar, or move the WordPress admin bar to the bottom of your pages. This answer will keep the WordPress admin bar right where it belongs… At the top of your pages.
Please note this will take a few short steps to complete, but it’s worth it. It’s not really a complicated or time consuming process. I just wanted to make sure the explanation on how to do so was clear and easy to follow/understand.
Step 1
get_body_class();
to your theme’s<body>
tag.directory. Find
header.php
and open it.<body>
.<?php echo '<body class="'.join(' ', get_body_class()).'">'.PHP_EOL; ?>
After completing the three steps above, you have now successfully enabled your WordPress theme with WordPress body classes.
Step 2 (OPTIONAL!)
<body>
tag.By default, WordPress already provides a list of default classes to the HTML tag, if you are using the
body_class()
orget_body_class()
functions.If you view the source code of any rendered front-end page on your WordPress website, you will notice two of the CSS classes automatically added to the HTML
<body>
tag are “logged-in” and “admin-bar”.You will also notice those CSS class names are only added to the HTML
<body>
tag if the user is logged in, otherwise they won’t be added to the HTML<body>
tag.So if you don’t want to use the default WordPress CSS class names, you can add your own very easily.
functions.php
and open it.add_filter('body_class', 'mbe_body_class');
to the top of thefile.
The code:
Now, if you view the source code of any rendered front-end page on your WordPress website, if the user is logged in, you will see “body-logged-in” has been added to the HTML
<body>
tag, and if the user is logged out, you will see “body-logged-out” has been added to the HTML<body>
tag.Step 3
This is the section of code which will correct your theme to display both the WordPress admin bar, and your Twitter Bootstrap navigation properly, whether the user is logged in or logged out of your website.
functions.php
and open it.add_action('wp_head', 'mbe_wp_head');
to the top of the file.The code:
EDIT TO CODE
This version of the mbe_wp_head function includes a mobile-first media query, to ensure that your header is pushed down the proper distance. For mobile, the WP admin bar is 48px tall. After the 783px breakpoint, the admin bar shortens to only 28px tall.
There you have it. If the user is logged in, you should now have the WordPress admin bar at the very top of your page, immediately followed by your Twitter Bootstrapped navigation. If the user is logged out of your WordPress website, your Twitter Bootstrap navigation should still display appropriately at the top of your website.
Didn’t work for me, but I found a nice fix. In your header.php use the wordpress function to query if the toolbar is displayed, and then create an empty div below the navbar div:
you can try this:
if that does work for you (which it should!), then you’ll have to move the wp admin bar to the bottom by sticking the code below into a plugins folder or your functions.php file:
as an alternative you can use this plugin
i dont really like using plugins because most of theme load my script with bogus codes i dont need… solution 1 and 2 above works fine, but if it doesnt work for you, you can try solution 3 below:
That seemed to work for me fine without the 28px issues..
It didn’t work for me until I added this to the body tag:
Then it worked fine!
Fix for Bootstrap 2 & 3
navbar-fixed-top
to prevent overlapping of site menu with WordPress admin menuFix for Bootstrap 4
fixed-top
to prevent overlapping of site menu with WordPress admin menuPerfect! Just what I was looking for, however, I did something a little differently in step 3. Not sure that it matters but my code looks like this…
You mentioned adding in different places, but I have always done it like this and it seems to work just fine. Thanks for the fix!