Im working with a project where i want the wp_nav_menu to output other css classes for current_page, current_ancestor and remove other stuff like page-id and menu-id.
I have get some stuff working like remove the unessesary classes and id:s using a custom Walker. But i cant get the current_ancestor to change to another class.
here is what i have come up with until now:
class Clean_Walker extends Walker_Nav_Menu
{
/**
* @see Walker::start_el()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param int $current_page Menu item ID.
* @param object $args
*/
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
{
global $wp_query;
$class_names = $value = '';
$classes[] = ( $item->current ) ? 'sel' : '';
// $current_classes = array(
// 'current-menu-item',
// 'current-menu-parent',
// 'current-menu-ancestor',
// 'current_page_item',
// 'current_page_parent',
// 'current_page_ancestor'
// );
// foreach ($current_classes as $current_class )
// {
// if ( in_array( $current_class, $classes ) )
// {
// $classes[] = "active";
// break;
// }
// }
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$output .= '<li'. $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->title .' '. $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$attribute = ! empty( $item->attr_title ) ? '<span>' . esc_attr( $item->attr_title ) . '</span>' : '';
$item_output = '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID );
$item_output .= $attribute . $args->link_after;
$item_output .= '</a>';
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
I also needed the attribute-field to be inside a span for some styling. So the poblem is that i need to change "current_ancestor" to the class sel
.
The class sel are working on a "single-page" so the only problem comes when im one lvl deeper.
I have search WPSE but no luck. Thanks!
current_item_ancestor
?