Archived topic
create a sticky custom menu
4 replies · Started by jasond on September 30, 2019
hello
can you advise how can I create custom menu sticky on the page?
add_action( 'init', function() {
register_nav_menu( 'tour-menu', __( 'Tour Menu' ) );
} );
Thank you
Hi there,
That code will register a new menu location, but it won't do anything else.
Maybe a Navigation Widget along with a plugin like this would help?: https://wordpress.org/plugins/sticky-menu-or-anything-on-scroll/
Thanks Tom, is there any way i can add the sticky code directly to the function like what you are doing for generatepres sticky feature? I prefer using native code from the theme rather than installing another plugin
The code in the theme was built specifically for the main navigation, so it's not currently possible to point it elsewhere.
Good idea, though - I'll see if we can make it more extendable :)
There is a workaround for this. You can add your sticky menu items to the main navigation and give it a class name that you can hide in css and only display on the sticky menu when you start scrolling. For example, let's say you name the menu item title "sticky one" and give it a class name of sticky1. Your code would look like this:
.sticky1 {
display: none;
}
#sticky-navigation .sticky1 {
display:block;
}