Is there a way when using Wordpress’ menu feature to:
a) remove the dropdown and caret functionality from navbar on the parent page
AND
b) keep the parent page on the navbar active when viewing a child page?
Or should I just use some advanced php?
a)
b)
function roots_cpt_active_menu($menu) {
if (is_page('child')) {
$menu = str_replace('active', '', $menu);
$menu = str_replace('menu-parent', 'menu-parent active', $menu);
}
return $menu;
}
add_filter('nav_menu_css_class', 'roots_cpt_active_menu', 400);
replace the word child
and parent
with the slugs of actual pages.
Thanks so much! The second bullet point on ‘A’ did the trick.
Though, is there a way to have this apply to the primary navigation and not secondary?
you can use wp_nav_menu_args
filter (http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_nav_menu_args) like so:
function modify_nav_menu_args($args = '') {
if($args['theme_location'] == 'secondary_navigation') {
$args['depth'] = 2;
}
return $args;
}
add_filter('wp_nav_menu_args', 'modify_nav_menu_args');
just change the name secondary_navigation
to the name you used to register the menu.