简体   繁体   中英

Adding a class to ul in custom wordpress menu

I am trying to add a class to the default ul generated in a custom wordpress menu.

I have created the custom menu in the backend and set it up fine, after referencing the wordpress codex this is the code I am currently using:

<?php 
if ( has_nav_menu( 'main-navigation' ) ) { /* if menu location 'main-navigation' exists then use custom menu */
  wp_nav_menu( 
    array(  
        'theme_location' => 'Main Navigation',
        'menu_class'      => 'row',
        'items_wrap' => '<ul class="nav">%3$s</ul>',
        'walker'         => '',
        ) 
    ); 
}
?>

This is generating a div with a class of "row" wrapping around my ul but no class is added to the ul itself. I have seen many people with this problem online but no solutions.

Thanks.

You can achieve this with jQuery by targetting the ul element and adding a class like this:

$(".row ul").addClass( "CLASS-HERE" );

Try this extension from GitHub. It allows you to use Bootstrap navigation components in WordPress with easy.

https://github.com/twittem/wp-bootstrap-navwalker

你可以使用参数

 'menu_class' => 'nav-menu'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM