ionos

Saturday, January 11, 2014

How to manually specify the current active page with wp_nav_menu()

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;
}

No comments:

Post a Comment

Featured Post

Payza integration

Payza's Advanced Button in HTML Using simple HTML, you can integrate easily with Payza.Generate buttons and manage payment details f...

Most Popular