wordpress - Have pre defined menus when developing a theme -
i trying develop theme customizable menus, header menu options , footer menu options.
in theme menu page right now, in "select menu edit" there 2 menus editable , because manually added 2nd menu. in theme trying make similar to, there tons of pre made menus in "select menu edit" , did not add of those.
how can add pre defined selectable menu options theme?
like footer have 4 different parts, header have part etc..
i want more menus here
i know how add more here!
to create new menu location , menu, add code functions.php file:
add_action( 'after_setup_theme', 'register_my_menu' ); function register_my_menu() { register_nav_menu( 'header_menu', 'menu header' ); // change desired menu name $menu_header = wp_create_nav_menu('main menu'); if($menu_header > 0) { // set new menu location set_theme_mod( 'nav_menu_locations' , array( 'header_menu' => $menu_header ) ); } }
it register new menu location, create blank menu inside it. if need add items inside menu, check on wp_update_nav_menu_item
function.
then display in template (like header.php in case) :
<?php wp_nav_menu( array('menu' => 'header_menu' )); ?>
Comments
Post a Comment