0

I am using theme Twenty Fourteen, and to add a logo I made the header bigger with the following code:

 .header-main {
    min-height: 108px;
} 

It works, but now the header isn't sticky anymore and I don't know why. Can someone please explain why the header isn't working?

1 Answer 1

0

This is due to the theme's js.

in /twentyfourteen/js/functions.php:

    /*
     * Fixed header for large screen.
     * If the header becomes more than 48px tall, unfix the header.
     *
     * The callback on the scroll event is only added if there is a header
     * image and we are not on mobile.
     */
    if ( _window.width() > 781 ) {
        var mastheadHeight = $( '#masthead' ).height(),
            toolbarOffset, mastheadOffset;

        if ( mastheadHeight > 48 ) {
            body.removeClass( 'masthead-fixed' );
        }

        if ( body.is( '.header-image' ) ) {
            toolbarOffset  = body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;
            mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset;

            _window.on( 'scroll.twentyfourteen', function() {
                if ( _window.scrollTop() > mastheadOffset && mastheadHeight < 49 ) {
                    body.addClass( 'masthead-fixed' );
                } else {
                    body.removeClass( 'masthead-fixed' );
                }
            } );
        }
    }

You can see it checks the height, and then if it's larger than 48, removes the masthead-fixed class from the body.

You could either

a. run some js that fires after functions.js:

$(body).addClass( 'masthead-fixed' );

b. force the site-header to be fixed via CSS:

.site-header
{
    postion: fixed;
}

Note in both cases, you'll likely need to add larger top margins to other content to push it down so the header doesn't cover it.

2
  • Thank you, Andrew, for your answer. Unfortunately it doesn't work, at least the second option with CSS. I have insufficient experience to implement the first option that you described. But meanwhile I think it's better to shrink the header to 48px before getting fixed. I mean after scrolling the logo schooled be minimized and the header should have a height of 48 px. I think this must be something like a fade-in-function. You know what I mean. And you know how to do it?
    – pradhana
    Commented Nov 29, 2017 at 14:03
  • Oh, it works with CSS. (I just copied your code, but there was a misspelling...) But now happens what you described. I need to add larger top margins. How can I do it?
    – pradhana
    Commented Nov 29, 2017 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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