Home / functions.php / Add a custom CSS class to wp_nav_menu
  • How to Add a custom CSS class to wp_nav_menu

    add-a-custom-css-class-to-wp_nav_menu

    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.

    ( click code to copy )

    wordpress snippet : PHP

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

    ( WordPress codex functions, hooks, in this snippet. )

    add_filter, _n,