You need to first collect the menu locations, then set the primary menu location with the menu id.
// Set the menu to primary menu location
$locations = get_theme_mod( 'nav_menu_locations' );
$locations['primary'] = $primary_nav_menu_id;
set_theme_mod ( 'nav_menu_locations', $locations );
Here I assume ‘primary’ is theme location referring to ‘Primary Navigation’.
Related Posts:
- Add custom classes to anchor in wp_nav_menu
- Displaying wp menus by name without using theme locations
- My Admin bar covers my sticky navbar [closed]
- How to make navigation a list without a plugin? [duplicate]
- wp_nav_menu(), how to change class?
- How to add menu support to a theme?
- Select menu on browser resize
- Extend walker – navigation, adding data attribute to a tag
- How to highlight the current page in the nav menu?
- how to change WordPress menu markup/classes
- Custom Nav Walker Displaying Values in Sub Menu
- Where is definied the theme location for the main menu in a WordPress template?
- WordPress is adding margins and padding to my custom menu?
- How to make theme elements customizable in wordpress?
- Primary navigation menu & footer not showing in category / tag page
- Using a page as home, how do I prevent nav from setting both home and page links active?
- Where am I doing wrong in my theme menu?
- Admin: sub menu doesnt display under apperance when activate my themes
- 3 Level Deep Navigation Menu Not Showing All Levels
- How to add menù section to my WordPress template?
- Thesis -style Navigation
- how do i develop a global nav and local nav to be wordpress dynamic?
- Why is my container argument not working for wp_nav_menu() [closed]
- Some doubts about WordPress handle the horizontal main menu visualization
- Custom nav menu not showing
- how to create/register menu items that can be added to menus later
- Why nav_menu_css_class doesn’t work with apply_filters?
- Programatically Created Menu not Editable in Dashboard
- 3 Level Menu Navigation (3rd Level not displaying)
- Theme: dropdown hover menu not showing up in IE/Edge
- How can I show a custom WordPress menu anywhere I want on my website?
- Show all menu levels except top level. How to exclude top level of a menu?
- WordPress Menu item > Sub menu Class update
- Menu names not getting translated
- Need help with adding custom wordpress menu and sub-menu
- How to achieve this navigation style in wordpress navigation
- Fallback dosen’t work when not using ‘menu’ attribute
- Primary Menu Showing All Pages With No Sub-Nav
- How to add drop symbol to parent nav items which have child
- WordPress 3.9 two menus in same position?
- What’s the policy for building a theme that doesn’t support widgets/menus?
- How to automatically set a Template Page Name next to a page in menu screen such as WooCommerce pages, front page, or posts page in wordpress?
- Dynamic nav menu with icons [closed]
- Menu items description? Custom Walker for wp_nav_menu()
- Sizing screenshot.png without losing aspect ratio
- Should `get_template_directory_uri()` be escaped?
- Page template in two level deep folder
- Child Theme not loading parent CSS
- Where do I find the functions triggered within a hook?
- Use of undefined constant FS_CHMOD_DIR – assumed ‘FS_CHMOD_DIR’
- Replace Home with image link inside custom header menu
- index.php is not loaded for single posts
- Why use while over if in single wordpress posts?
- WordPress website loads but is not displayed until page scrolled
- How do I add a post to a menu
- How to set page template on front using starter content?
- Different Admin Theme – Based on Role?
- Finding Page Template and Displaying Content
- how to set more than one menus to the same theme location
- Override Constants in Child theme
- Custom Nav Walker to show siblings and children of current branch?
- How to correctly add JQuery in a WP theme?
- how to change a theme slug
- Removing feeds from header using a function?
- I want to get the home root path
- How to add code in the content area in a WordPress theme?
- Translation Issue with WordPress Theme Check in comment_form function
- Using esc_url with a hard coded url
- Broken template went invisible
- How to edit theme functions file to modify pagination?
- Custom Nav Walker Trouble
- Issue on Adding A Class to Bootstrap Navbar Walker Dropdown
- Renaming a theme so it aids SEO and the theme used is hidden
- WordPress 3.8 Backend Admin Color Scheme add more scheme how to do?
- Theme thumbnail in dashboard
- How to change the theme directory uri for localhost?
- featured content: which area does this cover [closed]
- Which cache is kicking
- Customizer: get_preview_url() inside customize_save_after hook
- How to modify mobile nav menu text in theme
- Is there a way to switch to another theme?
- New to WordPress – Read the Codex, Other Docs; Still Confused
- Why in this WordPress theme I can’t see the Main Menu?
- How do I implement jPanelMenu?
- When trying to set title, not sure how to edit it for different pages
- Does wordpress add their own classes into nav menus?
- Post archives link yields a 404 Not Found
- static front page ONLY for certain themes?
- How to add cropped custom header image?
- Any way to change/add to the theme name dynamically?
- Let user to upload multiple time
- Different WP Rest API custom endpoints across different themes
- register_theme_directory() sees custom themes directory, but blank frontend
- wp_nav_menu custom walker class
- How to create multiple pages in a client theme?
- Theme customizer live preview JS- Trying to bind to an html image url without luck
- Purchased Theme to Custom Made Theme? [closed]
- How to make website with many template that active [closed]
- Image Size wrong during upload
- Correct way to make a custom block theme responsive