I tried few tutorials. All i think is i should use register_nav_menus()
and then add the menu in header.php
Here is the code i tried in functions.php from this help site itself
function my_cool_menu_function(){
register_nav_menus( array(
'primary' => 'Primary Navigation'
));
}
add_action( 'after_setup_theme', 'my_cool_menu_function' );
In header.php
<?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
When i tried to check whether any menu is registered with this function $locations = get_nav_menu_locations();var_dump($locations);
I got array of size zero. i,e no menu registered.
Am i missing something?
I can able to see few links in frontend which are pages i guess.
I see that Your theme does not natively support menus, but you can use them in sidebars by adding a “Custom Menu” widget on the Widgets screen.
So i think above menu is not registered.
What wrong am doing here?
I have added add_theme_support('nav-menus');
too in functions.php
Updates
I tried the same above code through plugin then i can able to see the menu. Which mean it is not working with the theme functions.php file. Am not sure why this happens.
Do anyone know this?
add_action( 'after_setup_theme', 'my_cool_menu_function' );
toadd_action( 'init', 'my_cool_menu_function' );