X

How to Customize Navigation Menu in WordPress with wp_nav_menu

Snippets by IsItWP

Want to customize your navigation menu in WordPress by adding a custom class to wp_nav_menu? It’s easy with our code snippet. In this article, we’ll show you how to add a custom class to wp_nav_menu.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

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

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 62 best free WordPress blog themes or 7 best WordPress contact form plugins.

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 Cancel reply

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!