1
votes

I am starting theme development with bootstrap. I got problem with navigation menu.

In header.php

wp_nav_menu( array(
            'theme_location'    => 'primary',
            'container'         => 'nav',
            'container_class'   => 'navbar-collapse collapse',
            'menu_class'        => 'nav navbar-nav navbar-right'
        ));

In functions.php

register_nav_menus( array(
    'primary' => esc_html__( 'Primary Menu', 'test1-wp-theme' ),
) );

What's wrong here ? I am newbie and developing wordpress theme for first time

Here is full header.php

<?php
/**
 * The header for our theme.
 *
 * This is the template that displays all of the <head> section and everything up until <div id="content">
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package T1_WP
 */

?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/assets/css/bootstrap.min.css">
<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/assets/css/main.css">

<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>
<div id="page" class="site">
    <a class="skip-link screen-reader-text" href="#content"><?php esc_html_e( 'Skip to content', 'test1-wp-theme' ); ?></a>
<nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">ABC Blog</a>
        </div>
        <?php
            wp_nav_menu( array(
                'theme_location'    => 'primary',
                'container'         => 'nav',
                'container_class'   => 'navbar-collapse collapse',
                'menu_class'        => 'nav navbar-nav navbar-right'
            ));     
        ?>      

      </div>
    </nav>

    <div id="content" class="site-content">

UPDATE

I have removed all array items, now it's working. But I didn't understand what's exact problem ?

<?php
            wp_nav_menu( array(

            ));     
        ?>  
1
Your code seems okay, did you assign a menu to primary menu location? - Vidya L
just add <?php wp_nav_menu( array('menu' => 'primary','theme_location'=>'primary','menu_class'=>'nav navbar-nav navbar-right ' )); ?> Looks like issue of container - PHP Team
Thanks, It's working now :) - Madan Bhandari
Have you solved this problem? What is happening exactly with your menu? Is not showing up? If you solved it please add the answer with the solution, if not add your functions.php code to your question in order to have more information - Adriana Hernández

1 Answers

2
votes

In Your header.php put below code and try

<div id="navbar(Id Name)" class="your class name">
    <?php
                wp_nav_menu( array(
                    'menu' => 'primary',
                    'theme_location'    => 'primary',
                    'container_class'   => 'navbar-collapse collapse',
                    'menu_class'        => 'nav navbar-nav navbar-right'
                ));     
    ?>   
</div>