WordPress Admin Bar pushed Sticky Footer off the bottom of the page

The footer is pushed out because WP will add margins to your page whenever the admin bar is set to show. The function responsible for this is called _admin_bar_bump_cb() and is located at wp-includes/admin-bar.php. The bad news is that it uses a harcoded 28px setting (meaning you won’t be able to fetch it and use it in your functions), along with an “!important” declaration, which you won’t be able to consistently override in order to avoid height changes in the future.

I think your best bet would be to check if the admin bar is showing and adjusting the footer accordingly. This should be as simple as adding this to your functions.php:

add_action('wp_head', 'adjust_sticky_footer');
function adjust_sticky_footer() {
    if(is_admin_bar_showing()) { ?>
        <style type="text/css">
            .footer { /* Adjust selector according to your theme */
                bottom: 28px;
            }
        </style>
    <?php
    }
}

I’m assuming your footer already has position: relative assigned to it, as per the example on the link you’ve provided.

Leave a Comment