Answer the question
In order to leave comments, you need to log in
wp_nav_menu remove li ul leave and add asset class for current page and child?
Friends, hello!
Help me to understand.
There was a task in wp_nav_menu to remove the wrapper ul, li and add an active class for the link.
I successfully completed this task.
Removed wrapper ul, li
<?php
$headerMenu = array(
'theme_location' => 'header_menu',
'container' => '',
'echo' => '',
'items_wrap' => '%3$s',
'depth' => 0
);
echo strip_tags( wp_nav_menu( $headerMenu ), '<a>' );
?>
function filter_nav_menu_link_attributes( $atts, $item, $args ) {
if ( $args->theme_location === 'header_nav' ) {
if ( $item->current ) {
$atts['class'] .= 'active';
};
if ( $item->current_item_parent ) {
$atts['class'] .= 'active';
}
}
return $atts;
};
add_filter( 'nav_menu_link_attributes', 'filter_nav_menu_link_attributes', 10, 4 );
Answer the question
In order to leave comments, you need to log in
21 views and not one answer.
In principle, I figured it out myself, but, based on the topics I read, I got the impression that only easy questions are answered here. ))
People. Hare keep your tongue in your ass.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question