[Resolved] Making Sticky Nav Work with Admin Bar Disabled

Home Forums Support [Resolved] Making Sticky Nav Work with Admin Bar Disabled

Home Forums Support Making Sticky Nav Work with Admin Bar Disabled

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #2241358

    I’m working on a site where I need the admin bar to go away for non-admin users, and as seems sometimes to happen, the standard disabling method via action hook after_setup_theme isn’t fully removing the admin bar in this case — which has led me to a css-based workaround that simply “undisplays” the admin bar.

    My solution is successful in disappearing the admin bar. The problem I now have, however, is that the sticky nav transition doesn’t work. When the admin bar is disappeared the way I’ve accomplished it, in other words, the sticky navigation div displays as expected when scrolling down-page, but it does not switch back to non-display on scrolling to top of document.

    I gather that this is because the value for document position relative to viewport that GeneratePress code looks for to trigger the sticky transition with admin bar present in the document isn’t the value now being given when we scroll to top. Is there a straightforward way to adjust for this — that is, to use instead the 32px-height-difference I need it to look for, with the admin bar undisplayed?

    Customer Support

    Hi Paul,

    We can first try hiding the admin bar through the show_admin_bar filter instead.

    Can you try adding this PHP snippet instead?:

    add_filter( 'show_admin_bar' , 'my_function_admin_bar');
    function my_function_admin_bar($show_admin_bar) {
        return ( current_user_can( 'administrator' ) ) ? $show_admin_bar : false;

    Reference: https://developer.wordpress.org/reference/hooks/show_admin_bar/

    Once you’ve added this filter, we’ll try to address the sticky nav.

    Kindly let us know how it goes!


    Ha, I should have studied show_admin_bar more closely before assuming the way I’d been hiding the bar on other projects (which does use show_admin_bar, but deploys it via after_setup_theme) was the “standard method.” That does the job thoroughly — and I can get rid of my css workaround.

    Sorry for the the clumsy inquiry! And thank you for the helpful redirection.

    Customer Support

    You’re welcome Paul!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.