Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

Is there a way to change the child <ul class="sub-menu"> generated by WordPress itself to a custom class name?

I know the parent <ul> you can remove or change the name with 'menu_class' => 'newname'.

I couldn't find the answer. I Tried 'submenu_class' => 'customname'. It seems logical to me, but obviously, that is not the right one.

any ideas?

1 Answer

0 votes
by (106k points)

There is no option to change the child <ul class="sub-menu"> generated by WordPress itself to a custom class name, One thing you can do is you can extend the 'walker' object that WordPress uses to create the menu HTML. By this way, only one method needs to be overridden below is the code that you can use:

class My_Walker_Nav_Menu extends Walker_Nav_Menu {

function start_lvl(&$output, $depth){

$indent = str_repeat("\t", $depth);

$output .= "\n$indent<ul class=\"my-sub-menu\">\n"; 

  }}

You can pass an argument to wp_nav_menu as follows:-

'walker' => new My_Walker_Nav_Menu()

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...