Hello reader's, In this post we discussed about "How to set Menu location in wordpress".
You can use the below code for creating menu and set their location, when you import data file in xml.
You can put this code into functions.php file
<!--?php
/* Add Menu */
add_action( 'after_setup_theme', 'pinboard_setup' );
if ( ! function_exists( 'pinboard_setup' ) ):
function pinboard_setup()
{
add_theme_support( 'post-thumbnails' );
register_nav_menus( array(
'primary' =&gt; __( 'Primary Navigation', 'pinboard' ),
'secondary' =&gt; __( 'Secondary Navigation', 'pinboard' ),
) );
}
endif;
**
* Set Menu location.
* Set with menu id
* Default Set
*/
$menus = wp_get_nav_menus();
$setMenu = get_theme_mod('nav_menu_locations');
for( $mi=0;$mi<count($menus);$mi++ ) {
if( $menus[$mi]-&gt;name == 'Header Menu' ) {
$menu_id = trim( $menus[$mi]-&gt;term_id );
$setMenu['primary'] = $menu_id;
set_theme_mod('nav_menu_locations', $setMenu);
}
elseif( $menus[$mi]-&gt;name == 'bottom menu' ) {
$setMenu['secondary'] = $menus[$mi]-&gt;term_id;
set_theme_mod('nav_menu_locations', $setMenu);
}
}
0 Comment(s)