How to add active class on current menu item page?
How to add active class on the current menu item page?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and shareâ âtheir programming âknowledge and build their careers.
add_filter(ânav_menu_css_classâ, âadd_active_classâ, 10, 2 ); function add_active_class($classes, $item) { if( $item->menu_item_parent == 0 && in_array(âcurrent-menu-itemâ, $classes) ) { $classes[] = âactiveâ; } return $classes; }
WordPress wp_nav_menu Code
wp_nav_menu(array(âtheme_locationâ =>âprimaryâ,âmenu_classâ => ânavigationâ))
âfunctions.phpâ is stored with each Theme in the Themeâs subdirectory in wp-content/themes. Each theme has its own functions file, but only the âfunctions.phpâ in the active Theme affects how your site publicly displays. If your theme already has a functions file, you can add code to it. If not, you can create a plain-text file named âfunctions.phpâ to add to your themeâs directory.WordPress active page Code
add_filter(ânav_menu_css_classâ, âadd_active_classâ, 10, 2 ); function add_active_class($classes, $item) { if( $item->menu_item_parent == 0 && in_array(âcurrent-menu-itemâ, $classes) ) { $classes[] = âactiveâ; } return $classes; }