How to Add a Sticky Menu to the Genesis Sample Theme

Yesterday I launched the new design here on my site, which includes a number of things that are new to my personal theme. In other words, things I’ve never used before.

One of those is what’s known as a “sticky menu”, and it’s something that I really wanted to incorporate when I began the redesign process.

If you don’t know what I’m talking about, take a look at the top of the screen right now. Since you’re reading this, you’ve scrolled down far enough to trigger the sticky menu.

Now scroll back to the top of the page, and you’ll see the sticky menu disappear, giving way to the default header and navigation of my site.

As expected in yesterday’s comments, I was asked how this was implemented. To your surprise, as it was to mine, this is something that is really easy to do.

Adding a Sticky Menu

There’s only a few steps required to create a sticky menu for your site, so go ahead and download the Genesis Sample theme as you’ll need it to follow the steps I mention below. If you are using a StudioPress or custom theme, this will merely serve as guidance.

You’ll need to create a custom menu through the WordPress dashboard, as the sticky menu that is shown at the top of your site will be displaying the secondary navigation.

Moving along, there is 3 sets of code that you need to implement. You can see those at the bottom of this post — functions.php, sticky-menu.js and style.css.

1. functions.php

There are two things you need to add to your theme’s functions file. The first is the function that will enqueue the sticky-menu.js file and the second is the function that will reposition the Secondary Navigation menu at the top of your page.

2. sticky-menu.js

In your theme’s folder, create another folder called js, and then create a new file called sticky-menu.js and place that inside. This file includes the jQuery that will control the fade in/out effect on the sticky menu for your site. Here’s what the path should look like:

genesis-sample/js/sticky-menu.js

3. style.css

Lastly, you’ll see that I’ve provided a bit of CSS that can be applied to your sticky menu to help make it stand out. Feel free to modify or add to this as necessary. To get your menu links to align right, assign them the sticky-right menu class in the CSS Classes option.

Want to see what the sticky menu should look like? Check out the demo site.

Email Newsletter

Like what you read here in this blog post?
Get more like it delivered to your inbox daily.

Comments

  1. says

    Very nice solution for a sticky header. I knew the principle from in-fading ads at the bottom of a page, when you scroll down. I also saw the fading sticky header for social buttons. Also a good thing to use that for.

  2. says

    Brian, simple jQuery made the trick here. I almost plucked my hair out by trying it using CSS only. Its time to add a sticky menu on my blog. Thank you.

      • says

        Interesting!
        It’s a stylish way of handling that. SO much better than those ones that awkwardly follow you down the side of a page, like the salesman who is sticking his foot in your door and saying “Look at me!” :-)

  3. says

    I love it!
    I got it working on my own site very easily. – Thank you

    One question: I am using responsive Studio Press Minimum Child Theme. I see your sticky menu is responsive…. mine, sadly is not. It must be something I missed in my CSS…
    tip or suggestion?
    Thanks again,
    CB

  4. says

    This is pretty cool and I’ve had to do this for clients from time to time. There are 2 optional tweaks you can do differently.

    First is you can avoid hardcoding the integer that triggers the menu to show up. Typically what I do is set it to the header height (or header height + XX px if desired). So you could do:

    var header = $(‘#header’).height();

    Then in the code where you have 200, you would simply swap that out for ‘header’. So the menu will truly only show once the header has scrolled off the screen (assuming your primary navigation is in the header widget area). This is also helpful if the size/height of your header fluctuates on different areas of the page.

    The other thing is placement of the navigation. Since you’re using position:fixed on the secondary navigation it doesn’t specifically need to be hooked into genesis_before. I usually do the opposite and render it at the very bottom of the page. I suppose it doesn’t matter, but out of habit, when search engines crawl my site, I want my header/title/h1 to be as close to the top of the page as I can, so I just output it at the bottom instead of the top.

  5. says

    Hello Brain
    I am using Streamline theme From Studipress for My Blog Can I use Sticky Themes Idea for it?
    Also I want to change the Layout of my theme so I can make it Look More Wide where Most of the Space is left empty on the Layout. I want to Make it Broad so that Maximum Area Can be covered And the Layout Looks Wide and Hence completely Filled. Is there any way to do that?

  6. says

    Brian excellent stuff… just trying it out on a local demo site, question… the sample code doesn’t seem to be ‘responsive’ like your site… have I missed anything?

  7. says

    Hi,

    I just added this to my first Genesis Child theme, But I have one problem. When I’m logged in the admin bar from WP covers the sticky navigation bar. Is there any way to fix this?

    Regards,
    Andor Nagy

  8. says

    It’s fantastic that you are incorporating some subtle jquery (since Scribble and Modern Portfolio). I like that Genesis is lean and mean and adding little touches like these really add that little detail that raises the experience. I think of these like the little tasty licks a musician plays that you notice but you don’t notice or that dash of spice that makes something taste really good, but you can’t really put your finger on it. Thanks for this tut, keep em comin.

  9. says

    Long time Genesis user, first time commenting. Brian, I love the look of the genesis sticky menu. I’ve added it to my site, which is now on the Modern Portfolio theme, but I can’t seem to figure out a way to remove the hover effect from my logo. Can you give me a hint on what I’m missing?

    Here’s the link: http://www.chantillypatino.com/

    Also, how can I get that great drop down search bar that you have?

    Great job on all the new design elements! Genesis just keeps getting better and better!

    • says

      Hey Chantilly, so sorry for the delay in response. Your comment was marked as spam for some reason. I’ll try to inspect your site with developer tools to see what’s going on. As for the search bar, that’s probably coming in another post. A little too difficult to explain in a comment.

      And thanks for commenting for the first time! :-)

  10. says

    Hello Brian,

    I loved the new navigation. But I was looking more than that. It will be quite not good for small screen devices. (I means devices having low resolution)

    A few days ago, I made a navigation somewhat like mashable. You may take a look on http://www.netrival.com.

    Waiting for your expert opinion. :)

  11. says

    Just awesome as always man, seriously. I wish I had the skills to do what you do, I really do. I actually started building websites because I am horrible working with my hands. I cannot build a simple bird house. But using your themes, and your tutorials, I can put out customized sites for myself, and clients.

    I hope one day I can buy you a cup of coffee man, you’ve made a non-talent like me look awesome :)

    Cheers

  12. says

    I was looking for something like this only. Menu where a user does need to scroll back to go back to categories. This post saved a lot of time.
    Thanks Brian

  13. says

    We’re launching a new look in three days and with a bit of CSS tweaking, this is going to be THE PERFECT FINISHING TOUCH on the new site. Using Genesis and a highly-customized theme that started as the “decor” theme, I didn’t have to modify any JS, CSS or PHP beyond your instructions to get it working. Now just to finalize the look…

    THANK YOU!!!

  14. says

    This is something really cool. Most of the times it is irritating if you have to scroll back to the top for selecting another menu. Another solution was ‘back to top’ button, but this is interesting.

  15. says

    Hi Brian,
    It’s a very effect when it’s working well.
    It’s not quite working with me yet. I guess the issue is that the targeted subnav menu is repositioned below the header. For this reason, upon activation of the above, the sub menu gets forced to the top of the screen and then disappears upon scroll. Is this a matter of simply changing the hooks? So far I have tried to no avail.

  16. says

    Hi Brian,

    Thanks so much for the awesome tutorial. This was the simplest one I’ve found to add this feature. It’s not quite working for me yet though. The top header appears when the page is first loaded, but then when I scroll down it disappears and never comes back. Do you have any idea why this might be happening? I’m very new to building websites so I don’t have too much technical knowledge. Thank you for your help.

    Ali

    • says

      I used a custom menu class to accomplish that. (and sorry for the long delay in your comment — as I mentioned in another one, it was buried in the spam for some reason.)

  17. says

    Any way to make this sticky menue mobile responsive because it’s messing up my blog when viewing it on a mobile phone. (iphone 4s).

    I like this menu and looking like I have to sacrafice mobile traffic to use this sticky menu. :(

  18. says

    Hey Brian. This looks awesome! I was wondering how you added the sticky menu and bam, you had a tutorial! Thanks for sharing this great tutorial, it looks perfect on the site. I just have one issue, is there a way to show the dropdown items on the menu? It’s not showing on my site.

  19. says

    I am shocked how fast and easy this one was. Thanks for a great tutorial Brian!

    (Love the new design…waiting patiently for a Studio Press version) :)

  20. says

    To those who have problem with this sticky menu, the issue is already solved if mobile plugin is used. I noticed this after I activated WPTouch in one of my client’s site.

  21. says

    Awesome! This is just what I was looking for last 2-3 days. I am using one of your theme on my blog and definitely gonna add this very soon. Thanks a lot :) . However, are you planning to update existing genesis themes to have this as a optional settings for user? I think that would be great.

  22. says

    Hey the sticky menu was working fine on my site but then I changed the theme and it did not work. Can you tell why? It happens normally or there is a flaw on my part?

  23. says

    Managed to get it working perfectly on my site. Apart from its not responsive on mine for some reason. Either way it still looks great. I tried a semi-transparent background colour also so people can still see the whole screen which I think works quite well. Thanks a lot for sharing all the code!

  24. says

    I am trying to implement this on my own web dev site. Not luck. I am using modern portfolio. My issue with a tutorial like this is having the correct location for the script files. Any help would be great!

  25. says

    It would be interesting to see this adapted to be used as a cta bar in the style of a hello bar. Or maybe instead of a sticky menu we could have a “sticky widget” are on top. Can’t wait for Genesis 2.0, and love the redesign for your blog Brian.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>