How to modify the nav menu structure or make custom menu structure in WordPress ?

If you want to modify the nav menu structure or make custom menu structure in WordPress then add this code to functions.php file.

class Nav_Walker_Nav_Menu_sitemap extends Walker_Nav_Menu{
  function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0){
     global $wp_query;
     $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
     $class_names = $value = '';
     $classes = empty( $item->classes ) ? array() : (array) $item->classes;
     $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
     $class_names = ' class="'. esc_attr( $class_names ) . '"';
     $output .= $indent . '

then declare the menu with new class like below example in your theme page.

wp_nav_menu( array(
    'theme_location' => 'sitemapmainpart',
    'walker' => new Nav_Walker_Nav_Menu_sitemap() 
 ) );
Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *