Archived topic
Disable sticky header navigation while scrolliong on blog posts
11 replies · Started by Stephen on May 20, 2020
Hello GeneratePress team,
Currently struggling to disable sticky nav on my blog posts but retain it on rest of website.
I've attempted to use this CSS to no avail:
.single .navigation-stick,
.single #sticky-placeholder {
display: none !important;
}
Please let me know what I can use to get it to work if possible!
Thanks in advance.
Hi there,
you can use this Filter to disable the navigation:
https://docs.generatepress.com/article/option_generate_menu_plus_settings/
For example:
add_filter( 'option_generate_menu_plus_settings','db_posts_disable_sticky_nav' );
function db_posts_disable_sticky_nav( $options ) {
if ( is_single() && 'post' == get_post_type() ) {
$options['sticky_menu'] = 'false';
}
return $options;
}
Sorry I've completely reworded my question. My fault entirely. In fact, I actually meant the complete opposite of what I have written haha!
My stick nav currently hides itself when scrolling down. I need it to stay sticky when scrolling up and down but only on blog posts. Apologies for wording everything wrong!
Thank you.
Same code applies just change the options :)
So in the code above replace:
$options['sticky_menu'] = 'false';
with:
$options['auto_hide_sticky'] = 'false';
Ok, so I've used the following in code snippets and I'm afraid it still isn't working:
add_filter( 'option_generate_menu_plus_settings','db_posts_disable_sticky_nav' );
function db_posts_disable_sticky_nav( $options ) {
if ( is_single() && 'post' == get_post_type() ) {
$options['auto_hide_sticky'] = 'false';
}
return $options;
}
Presumably I need to change 'db_posts_disable_sticky_nav' to something else but I'm not sure what, sorry!
Thank you for your patience David
Thats odd. Try this.
1. In Customizer > Layout > Sticky Navigation --> Uncheck the hide when scrolling down
2. The add this Snippet:
add_filter( 'option_generate_menu_plus_settings','db_posts_disable_sticky_hide' );
function db_posts_disable_sticky_hide( $options ) {
if ( !is_single() ) {
$options['auto_hide_sticky'] = 'true';
}
return $options;
}
This should now enable that feature whenever you're NOT on a single post.
Great, that has almost solved it. Only other thing is the nav bar now slides in on blog posts but I would like it to just stay in place. Is there a way I can do that too?
Please see example - https://www.cleardesign.studio/boost-your-social-media-following/
Thanks again
In Customizer > Layout > Sticky Navigation change the Transition to None
Spot on, thats solved it thanks so much David.
Try disabling autoptimize and any other cache plugins as i can still see the slide effect enabled on the site.
Sorry, I was mistaken with previous comment. All sorted now thank you
Glad to hear that