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.
Cool snippet.
Thanks for the tip.
E.g. http://www.kriesi.at/wp-content/uploads/2011/03/screenshot-2011-03-06-um-20.21.55.png . Look the options in menu page.
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?
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.
thanks kevin, let m know if you come up with anything
No problem will do.
No problem will do.
Hi. How to create a “mega menu”? This have a specific filter, but I dont know make it. Thanks.
I assume that you mean this kind of menu ?
http://www.sohtanaka.com/web-design/mega-drop-downs-w-css-jquery/
If so I spotted a few plugins
http://wordpress.org/extend/plugins/jquery-mega-menu/