简体   繁体   中英

Trying to convert bootstrap nav to wordpress by wp_nav_menu

I have a problem where the html nav has js and a few classes set up but I cant get them to transfer over to wordpress.

Original

<div class="collapse navbar-collapse" id="navbarResponsive">
    <ul class="navbar-nav ml-auto">
        <li class="nav-item">
            <a class="nav-link js-scroll-trigger" href="#services">Services</a>
        </li>
        <li class="nav-item">
            <a class="nav-link js-scroll-trigger" href="#portfolio">Portfolio</a>
        </li>
        <li class="nav-item">
            <a class="nav-link js-scroll-trigger" href="#about">About</a>
        </li>
        <li class="nav-item">
            <a class="nav-link js-scroll-trigger" href="#team">Team</a>
        </li>
        <li class="nav-item">
            <a class="nav-link js-scroll-trigger" href="#contact">Contact</a>
        </li>
    </ul>
</div>

What I have so far

Wordpress php

$defaults = array(
    'container' => 'ul',
    'theme_location' => 'primary-menu',
    'menu_class' => 'navbar-nav ml-auto'

);

wp_nav_menu($defaults);

If you need to see entire theme: https://startbootstrap.com/template-overviews/agency/

The following code will get you the whole menu markup you included in the question.

<?php
  $defaults = array(
      'container' => 'div',
      'container_id' => 'navbarResponsive',
      'container_class' => 'collapse navbar-collapse',
      'theme_location' => 'primary-menu',
      'menu_class' => 'navbar-nav ml-auto'
  );

  wp_nav_menu( $defaults );
?>

The classes for li and a items still need to be taken care of. You can use custom nav_walker for that.

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