jprieton / wp-bootstrap4-navwalker

A custom WordPress nav walker class to fully implement the Twitter Bootstrap 4.x navigation style in a custom theme using the WordPress built in menu manager
GNU General Public License v3.0
40 stars 56 forks source link

Menu Configuration #10

Open tinhop opened 5 years ago

tinhop commented 5 years ago

Hello, I am creating an HTML page with bootstrap 4, and my idea is to configure it to walk with wordpress and its cms environment, the texts and other settings with Custom Fields and now in the final stages I am having problems configuring my menu, I was recommended to use your plugin, but I am having problems configuring it. I tried the base installation, but I did not get it, so I am seeing to change the lines of code within the pages that you indicate, but I am not getting it

i got this lines acording to the menus on my functions.php file

/*menues support*/

add_theme_support('menus');

/*register menues*/

register_nav_menus(

    array( 
            'top menu' => __('Top Menu', 'theme'),
        )

    );

    // Register Custom Navigation Walker
require_once get_template_directory() . '/wp-bootstrap-navwalker.php';

and then on mi header.php file

<body>

 <header>
  <div>
   <?php
$custom_logo = wp_get_attachment_image( get_theme_mod( 'custom_logo' ), 'full' );
?>

<nav class="navbar navbar-light bg-light navbar-expand-lg justify-content-between">

  <a class="navbar-brand" href="<?php echo home_url() ?>">
    <?php echo $custom_logo ?>
  </a>

  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <?php
  wp_nav_menu( array(
      'theme_location'  => 'top-menu',
      'depth'           => 2,
      'container'       => 'div',
      'container_id'    => 'navbarNavDropdown',
      'container_class' => 'collapse navbar-collapse',
      'menu_class'      => 'nav navbar-nav ml-auto',
      'fallback_cb'     => 'WP_Bootstrap_Navwalker::fallback',
      'walker'          => new WP_Bootstrap_Navwalker()
  ) );
  ?>
</nav>
  </div><!--container-->
  </header>

and what the page returns to me in preview mode is this, and I can't configure the menu with the corresponding links

image

jprieton commented 5 years ago

Hello, when register nav menus you use this code

register_nav_menus(
    array( 
            'top menu' => __('Top Menu', 'theme'),
        )
    );

And when you call the menu in the args use

 'theme_location'  => 'top-menu',

Notice the difference in the menu id; 'top menu' when is declared and 'top-menu' when is used in args

EDIT The menu ID should be like a slug, without spaces