6

Please help with menu registeration:

I have followed this guide (http://codex.wordpress.org/Navigation_Menus) step by step.

Added the following code to functions.php:

function register_my_menus() {
  register_nav_menus(
    array('header-menu' => __( 'Header Menu' ) )
  );
}

add_action( 'init', 'register_my_menus' );

But the guide says that this will make the menu appear in the Appearance -> Menus admin screen in the "Theme Locations" box as "Header Menu".

When I go to Appearance -> Menus everything is greyed out and there is no option of "Theme Locations"

1
  • Add a screenshot of wp-admin/nav-menus.php. And do something with your other orphaned questions.
    – fuxia
    Feb 26, 2012 at 4:49

1 Answer 1

7

You don't need to add any action to register your Nav Menu. Here are some quick steps for you to get your Wordpress Nav Menu to work...

Register Nav Menu

if (function_exists('register_nav_menu'))
{
    register_nav_menu('header_menu', 'Header Menu');
}

Define and Use Nav Menu in your Theme: Usually we place the Menu DIV code in header.php file; so I assume yours is also in header.php file. Open that file and locate the DIV container where you wish your Wordpress NAV menu to appear. Here is a sample from one of my recent Wordpress themes for your ready reference:

<div class="css-nav" >

<?php wp_nav_menu( array(
    'sort_column' => 'menu_order',
    'theme_location' => 'header_menu',
    'menu_class' => 'css-menu',
    'title_li' => '<div class="l"></div>',
    'link_before' => '<span class="l">',
    'link_after' => '</span>'
) ); ?> </div>

Once you add this code, go to your WP Admin - Menus. Create a new Menu, if you don't have any yet. As soon as you create a menu, you should see "Theme Location" meta box to the left side of your Menu Item arranger area.

I hope this helps. :-)

Cheers,

Ruturaj.

4
  • +1 for a well-formatted, good answer from a new user. Welcome to WPSE. :)
    – Jared
    Feb 26, 2012 at 5:09
  • 5
    function_exists('register_nav_menu') doesn't do anything useful: nav-menu.php is loaded before the theme’s functions.php (see wp-settings.php). 'sort_column' and 'title_li' are not valid arguments.
    – fuxia
    Feb 26, 2012 at 5:28
  • Thanks...This works! Finally! Documentation at Wordpress could use a serious update Feb 26, 2012 at 5:38
  • Wow! One of the 3 menu locations appeared as soon as I put down if (function_exists('register_nav_menu')) , but how do I make the other two show up? ` if (function_exists('register_nav_menu')) {` register_nav_menus('headerMenuLocation', 'Header Menu Location'); register_nav_menus('footerLocationOne', 'Footer Location One'); register_nav_menus('footerLocationTwo', 'Footer Location Two'); }
    – YCode
    Sep 17, 2018 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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