WordPress – Adding Menu Support to Custom WordPress Theme

Wordpresswordpress-theming

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!)

Best Answer

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' ) ) {
    ...
}
Related Topic