douyan3478 2015-05-11 06:50
浏览 58

Wordpress在ul结尾处打印菜单名称

I have a secondary menu in my Wordpress-Theme, and it works - the only problem is that at the end of the ul-list it prints the menu-name.

The output is something like this:

<ul>
    <li><a>One</a></li>
    <li><a>Two</a></li>
    <li><a>Three</a></li>
    secondary
</ul>

I can´t find where this "secondary" comes from, as I did not ask Wordpress to do that ;)

In my theme´s functions.php I register my menus like this:

register_nav_menus( array(
    'primary' => 'Primary Menu',
    'secondary' => 'Secondary Menu',
) );

And in my footer I call the menu:

<?php wp_nav_menu( array( 'theme_location' => 'secondary', 'menu_id' => 'secondary-menu' ) ); ?>

It´s just a weird bug somewhere - I appreciate every hint or tip on how to fix this.

  • 写回答

1条回答 默认 最新

  • duankeng1911 2015-06-18 17:53
    关注

    Your menu registration looks different than the recommendation on wordpress. Have you tried setting it up like this? https://codex.wordpress.org/Navigation_Menus

    function register_my_menus() {
      register_nav_menus(
        array(
          'primary-menu' => __( 'Primary Menu' ),
         'secondary-menu' => __( 'Secondary Menu' )
       )
      );
    }
    add_action( 'init', 'register_my_menus' );
    

    then call just the secondary menu like this

    if ( has_nav_menu( 'secondary-menu' ) ) { /* if menu location 'primary-menu' exists then use custom menu */
      wp_nav_menu( array( 'theme_location' => 'secondary-menu') ); 
    }
    

    Source: http://www.paulund.co.uk/how-to-register-menus-in-wordpress

    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计