dtxf759200 2015-05-13 08:01
浏览 73
已采纳

如何从wordpress的Walker_Nav_Menu中删除<div class =“menu”>

I want to remove <div class="menu"> from Walker_Nav_Menu ,I am getting default <div class='menu'> in menues ,I have tried to rename container in but it is not working

<div class="menu">
<ul>
<li class="page_item page-item-66"><a href="http://localhost/wp/about-us/">About Us</a>
</li>
<li class="page_item page-item-72"><a href="http://localhost/wp/contact-us/">Contact us</a></li>
<li class="page_item page-item-70 current_page_item"><a href="http://localhost/wp/enquiry/">Enquiry</a></li>
<li class="page_item page-item-74"><a href="http://localhost/wp/home/">Home</a></li>
<li class="page_item page-item-68"><a href="http://localhost/wp/product/">Product</a></li>
<li class="page_item page-item-2"><a href="http://localhost/wp/sample-page/">Sample Page</a></li>
</ul>
</div>

code to print menu

<?php wp_nav_menu( array( 'theme_location' => 'main-menu' ) ); ?>

$defaults = array( 'menu' => '', 'container1' => '', 'container_class' => 'false', 'container_id' => '', 'menu_class' => '', 'menu_id' => '',
    'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
    'depth' => 0, 'walker' => '', 'theme_location' => '' );
  • 写回答

2条回答 默认 最新

  • dongtiran7769 2015-05-13 08:23
    关注

    All you need to add is false in container argument to achieve this.So it will be something like container=>false.

    But it will only work if you have correct theme_location. For an example, If you are using default menu in wordpress without creating any menu or without assigning any location to created menu, then above suggestion will not work.

    So to make it work, create menu and assign location to it and make sure your wp_nav_menu also contains same location.

    Edited

    Replace your theme's header.php Line 21 with following code:

    <?php wp_nav_menu( array( 'theme_location' => 'main-menu', 'container'=>false, 'menu_class'=> 'your_class_name' ) ); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?