简体   繁体   English

在自定义wordpress菜单中向ul添加类

[英]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. 我试图将一个类添加到自定义wordpress菜单中生成的默认ul。

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: 我在后端创建了自定义菜单,并将其设置好,在引用wordpress Codex之后,这是我当前正在使用的代码:

<?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. 这将生成一个带有围绕我的ul包裹的“行”类的div,但没有将任何类添加到ul本身。 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: 您可以使用jQuery通过实现ul元素并添加如下类来实现此目的:

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

Try this extension from GitHub. 从GitHub尝试此扩展。 It allows you to use Bootstrap navigation components in WordPress with easy. 它使您可以轻松地在WordPress中使用Bootstrap导航组件。

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

你可以使用参数

 'menu_class' => 'nav-menu'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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