I’m trying to create a theme which when activated, sets up a primary navigation, adds the homepage to it and then enables it in the correct location.
Here’s what I’ve got so far:
register_nav_menu('Primary', 'Primary Navigation');
$primary_nav_menu_id = wp_create_nav_menu('Primary');
wp_update_nav_menu_item($primary_nav_menu_id, 0, array(
'menu-item-title' => __('Home'),
'menu-item-classes' => 'home',
'menu-item-url' => home_url( '/' ),
'menu-item-status' => 'publish'
));
The above creates the menu, adds a link to the homepage but how would I go about automatically assigning this menu a theme location of ‘Primary Navigation’?
Is this possible?
You need to first collect the menu locations, then set the primary menu location with the menu id.
Here I assume ‘primary’ is theme location referring to ‘Primary Navigation’.
The other answer is the short version for this. However, I made a function, that does a bit more. It does this:
nav-mobile