6

I am creating my first Wordpress theme and I am struggling with menu support:

I added a custom menu in functions.php and implemented it into my header.php like shown below but the menu-option in the administration area does not show up!

# functions.php

<?php

    add_theme_support( 'menus' );

    add_action( 'init', 'register_my_menus' );

    function register_my_menus() {
        register_nav_menus(
            array(
                'primary-menu' => __( 'Primary Menu' ),
                'secondary-menu' => __( 'Secondary Menu' )
            )
        );
    }

?>

# header.php
# [...]
    <?php wp_nav_menu( array( 'theme_location' => 'primary-menu' ) ); ?>
# [...]

My Setting:

  • Wordpress Version 3.4.2
  • MAMP Development Environment
  • No plugins

Other information:

  • The menu option shows up in other templates
  • The menu is getting rendered correctly on the page

What am I missing here?


Edit #1

I can't even see the menu option in the admin menu (like here!)

2
  • Are you able to see the "Secondary Menu" dropdown on Theme Locations at menu dashboard? Commented Sep 27, 2012 at 8:31
  • No I don't see that. (I edited the question.) Commented Sep 27, 2012 at 8:44

1 Answer 1

10

Few things - You don't need add_theme_support(); nor the add_action('init', 'register_my_menus')

Just straight up call the register_nav_menus function, like so:

register_nav_menus(
    array(
    'primary-menu' => __( 'Primary Menu' ),
    'secondary-menu' => __( 'Secondary Menu' )
    )
);

Can also check if the function exists if you desire. But if it's only for use on your own theme and you know it exists it's not really needed.

if ( function_exists( 'register_nav_menus' ) ) {
    ...
}
Sign up to request clarification or add additional context in comments.

3 Comments

Oh man... I named the file function.php instead of functions.php. Call me idiot -.-
actually you should use it with add_action( 'init', 'register_my_menus' ); codex.wordpress.org/Navigation_Menus
Yes, so register_nav_menus() defines one or more menu locations. As long as you have at least one menu location defined, WordPress will allow you create menus, even though you are not required to link any of those menus to a menu location. I’m sure that design must have made sense to someone at the time (a long time ago).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.