Custom WordPress Admin Bar CSS

If you have logged in to (almost) any WordPress site since version 3.1, you have probably seen the admin bar at least once. At first it was a nuisance for most people, a very popular blog topic was how to disable that annoying bar at the top of the screen. Just take a look at the search results!

I feel like we’ve now come to love the admin bar, it is no longer a thorn in our side while we create WordPress sites. Plugins are taking advantage of it by adding their own buttons and twist to it. It also has received a bit of a makeover recently with the WordPress 3.8 release.

On some sites the admin bar can still get in the way a bit though. Most recently I was customizing the WooCommerce Store Notice bar that can be enabled and needed to adjust the CSS that WordPress by default adds to move the site below the admin bar.

I thought to myself that this being WordPress, it is most likely filterable, but it was not.

So I thought since this is a function with callback in it’s name I can remove it and add my own action, and that is possible. But the way the action is added, made me look just a little deeper. The callback function’s name is taken from the arguments from the add_theme_support()
function, just a few lines above the hook.

So instead of removing and adding an action, why don’t we just pass our custom callback to begin with!

This is very simple to do. By default all theme’ssupport the admin bar. However you can still use the add_theme_support() function to pass your own arguments.

Here you’ll notice there are really only two additions, theadd_theme_support() function and the function adding the CSS. Just customize the CSS to your own needs and you are all set!

How does this affect WooCommerce?

If you run WooCommerce and display the demo notice, while also displaying the admin bar, you can get some questionable results at times. What if you main navigation is at the very top of the screen and the demo notice just covered it completely?

What I have done to get around this is wrap theadd_theme_support()
function in an if statement that checks: