Reputation: 6338
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:
Other information:
What am I missing here?
I can't even see the menu option in the admin menu (like here!)
Upvotes: 6
Views: 18410
Reputation: 151
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' ) ) {
...
}
Upvotes: 10