Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I try to create simple menu in custom theme. WordPress version is 3.9.1 So I taking code from here, just change menu and container class / id for better debuging.

                    'theme_location'  => '',
                    'menu'            => '',
                    'container'       => 'div',
                    'container_class' => 'container_class',
                    'container_id'    => 'container_id',
                    'menu_class'      => 'menu_class',
                    'menu_id'         => 'menu_id',
                    'echo'            => true,
                    'fallback_cb'     => 'wp_page_menu',
                    'before'          => '',
                    'after'           => '',
                    'link_before'     => '',
                    'link_after'      => '',
                    'items_wrap'      => '<ul id="%1$s" class="%2$s">%3$s</ul>',
                    'depth'           => 0,
                    'walker'          => ''

But it creates this code:

<div class="menu_class">
        <li class="page_item page-item-2">
            <a href="http://localhost/?page_id=2">Пример страницы</a>

Instead of expected this:

<div id="container_id" class="container_id">
    <ul id="menu_id" class="menu_class">
        <li class="page_item page-item-2">
            <a href="http://localhost/?page_id=2">Пример страницы</a>

What i do wrong? Thank you.

UPDATED I already has this code at fuctions.php:


function bd_setup() {
    register_nav_menu( 'primary', __( 'Primary Menu' ) );

add_action( 'init', 'bd_setup' );

SOLVED After creation Menu in Appearance->Menu and assignation it in Appearance->Menu->Manage Locations I got expected code.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I tried your code it works perfectly fine for me, to give output as:

<div class="container_class" id="container_id">
<ul class="menu_class" id="menu_id">
   <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-154"><a href="">Funny</a></li>
   <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-159"><a href="">Jokes</a></li>
   <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-156"><a href="">Love</a></li>
   <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-155"><a href="">Motivational</a></li>
   <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-157"><a href="">Political</a></li>
   <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-158"><a href="">News</a></li>

I think you might be missing the argument 'theme_location', and founding no menu at that location the fallback "wp_page_menu" is being executed. Which doesn't use the classes you mentioned in the call to "wp_nav_menu".

In case you don't know what a 'theme_location' could be:

function register_my_new_menu() {
  register_nav_menus( array(
    'custom-menu'   =>  __( 'Custom Menu', 'the-bootstrap' )
    // Theme Location: custom-menu
    // Menu Name: Custom Menu
    // Create and assign a menu to this location in Dashboard->Menus
  ) );
add_action( 'after_setup_theme', 'register_my_new_menu' );

Apologies, if I get to basics that you already know.

share|improve this answer
Thank you for your answer. I already has similar code at functions.php. I think problem somwhere in Appearance -> Menu. After installation dedfault menu was not edited (created?). Is there any way to render right code just immediately after installing wordpress? –  Oleg2tor Jul 19 '14 at 22:42
Aha, sawed answer in your comment :) "Create and assign a menu to this location in Dashboard->Menus". I assume that it is normal practise in WP to create and assign menu for each theme? –  Oleg2tor Jul 19 '14 at 22:51
Advantage of WP is it's robust dashboard. So, we should care to use it at it's full. Yes, we create custom menu locations and assign a menu to it from the Menus Admin. –  OmAk Jul 20 '14 at 10:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.