最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

themes - Wordpress Menu Navigation links not working

programmeradmin1浏览0评论

Navigation Menu links not working, but the bootstrap CSS is working. Can anyone help me in getting the links working? Thank you

<ul class="navbar-nav mr-auto">            
      <?php
      wp_nav_menu(array(
        'theme_location' => 'primary',
        'before' => '<class="nav-item active">',      
        'menu_class' =>'navbar-nav mr-auto',
        'link_before' =>'<a class="nav-link" href="#">',      
        'link_after' =>'<span class="sr-only">(current)</span></a>', 
        'container' => false, 
        'items_wrap' => '%3$s'
      ));
      ?>
    </ul>

Navigation Menu links not working, but the bootstrap CSS is working. Can anyone help me in getting the links working? Thank you

<ul class="navbar-nav mr-auto">            
      <?php
      wp_nav_menu(array(
        'theme_location' => 'primary',
        'before' => '<class="nav-item active">',      
        'menu_class' =>'navbar-nav mr-auto',
        'link_before' =>'<a class="nav-link" href="#">',      
        'link_after' =>'<span class="sr-only">(current)</span></a>', 
        'container' => false, 
        'items_wrap' => '%3$s'
      ));
      ?>
    </ul>
Share Improve this question edited Apr 25, 2019 at 19:40 RiddleMeThis 3,8078 gold badges22 silver badges30 bronze badges asked Apr 25, 2019 at 18:47 Santosh KumarSantosh Kumar 32 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

Here are a couple things I noticed.

You don't want to include the <a> inside of link_before or link_after, you will get 2 links if you do that. You also don't need the <ul>. Instead I think you want something like this...

<?php
    wp_nav_menu(array(
        'theme_location' => 'primary',
        'before' => '<class="nav-item active">',      
        'menu_class' =>'navbar-nav mr-auto',
        'link_before' =>'<span class="nav-link">',      
        'link_after' =>'</span>', 
        'container' => false, 
        'items_wrap' => '%3$s'
    ));
?>

You should read more about wp_nav_menu.

The problem you're using dead link (#) in link_before. You can test removing "#" from link_before

    <ul class="navbar-nav mr-auto">            
          <?php
          wp_nav_menu(array(
            'theme_location' => 'headerMenuLocation',
            'before' => '<class="nav-item active">',      
            'menu_class' =>'navbar-nav mr-auto',
            // 'link_before' =>'<a class="nav-link" href="#">',
                                  //problem is here {href="#"}     
            // 'link_after' =>'<span class="sr-only">(current)</span></a>', 
            'container' => false, 
            'items_wrap' => '%3$s'
          ));
          ?>
        </ul>
发布评论

评论列表(0)

  1. 暂无评论