Add a custom CSS class to wp_nav_menu

Floating Social Bar Review - jetpack sharing

Adding this snippet to the functions.php of your wordpress theme will add a custom class to the wp_nav_menu navigation within your wordpress theme.

function custom_nav_class($classes, $item){
     $classes[] = “custom-class”;
     return $classes;
add_filter(‘nav_menu_css_class’ , ‘custom_nav_class’ , 10 , 2);

Comments  Leave a Reply

  1. Wordpress Themes August 20, 2012 at 12:24 pm

    Cool snippet.
    Thanks for the tip.

  2. Anton Samper Rivaya July 16, 2011 at 5:10 am

    hey kevin,  i’m looking into automatically adding children to parent pages on the wp menu. do you know if there is a quick snippet we can add to functions.php to make this happen?

    1. Hmmm I would have to think about that a bit, nothing that I can think of of the top of my head. Ill put that on my list of snippets to write for wpsnipp. If I find something ill be sure to send you a message. 

      1. Anton Samper Rivaya July 16, 2011 at 11:53 pm

        thanks kevin, let m know if you come up with anything

        1. No problem will do.

        2. No problem will do.

  3. Hi. How to create a “mega menu”? This have a specific filter, but I dont know make it. Thanks.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!