wp_create_nav_menu()
function accepts the menu name and not the menu location.
and as for wp_update_menu_item()
well its for items and not the menu itself.
After digging in the code i found out that “assignment” of ‘theme location’ to a menu is not done using of the nav_menu API in WordPress but with theme options so:
//first get the current theme
$theme = get_current_theme();
//get theme's mods
$mods = get_option("mods_$theme");
//update mods with menu id at theme location
$mods['nav_menu_locations']['header-menu'] = $menu_id;
update_option("mods_$theme", $mods);
hope this helps 🙂
Related Posts:
- The the_post_thumbnail without srcset?
- after_setup_theme always runs
- WordPress API Menu/Submenu Order
- What WP folder can I use to write files to?
- Can’t get staging site to display same way as live site. Completely stumped
- How to add default images for custom backgrounds?
- How to call the_excerpt() with tags or the_content() as an excerpt?
- Display a different theme for not logged-in users
- how to test a theme upgrade
- Custom Theme: The active theme is broken. Reverting to the default theme
- comment_form() generates the wrong action url
- How to set path with WP_Filesystem and ftp base / chroot
- How to add paging to query
- Have WP Theme update from Git Repository
- A two column loop with one lead post
- How to Modify a Widgets UL and/or LI Classes
- Help with “text domain”, comments_form in WordPress theme
- WooCommerce: VAT on grouped products
- Why is unfiltered html allowed in custom fields for author / contributor roles?
- Select front page and blog page in custom theme settings page
- Using the theme options to change background
- Getting the wrong page ID
- Avoid theme updates, just one theme
- Theme change only in CSS and a few images
- How do I save a wordpress theme’s files and install them on another site?
- Is there an action for save_menu and/or update_menu?
- Using AJAX in wordpress theme
- moving an admin submenu item to a top-level position
- Metadata Query when storing data as array possible?
- Excluding Pages not working
- show a post from a specific post format
- How to use different assets if local or live
- get_option() returning empty
- How can I add a custom button to the post editor toolbar?
- How to make the excerpt_more filter apply to the actual post excerpt?
- Default image size not working
- Customizer: save setting/control content to post/page
- Wp_customize_image_control Use Add Media
- Changing Header Image Every N Minutes/Seconds
- Post Content Displaying Below ALL Shortcodes Content
- WordPress Template Part in iFrame
- Can I add an icon & function to the “Upload/Insert” toolbar at the top of the content editor?
- underscores use of the article element on the page template
- Ideal inline dynamic CSS injection
- How to create and populate with few links a menu in child theme functions.php?
- Plugin does not work in custom theme
- How to Manually Code Shortcode?
- Consequences if using PHP include TEMPLATEPATH?
- Adding a gallery to my first theme
- Making custom woo themes
- Where does the uploaded image go?
- Headless WordPress + Vue.js on the same server
- Previous and Next links not populating, have I missed something?
- Single.php the_excerpt loads same as the_content not loading read more line
- Where to put custom page templates in theme?
- Is there a way to retrieve the calling template part?
- How to fix WordPress images not showing up in local hosted XAMPP server?
- Let user to add input fields on theme option page
- WP_Query not getting all posts, just tagged posts
- how to hide home nav link in wordpress
- .current_page_ancestor broken in Twenty Eleven
- MapPress Easy Google Map in Jquery Tabs Problem
- Homepage slider not using correct images
- Calling a WP Plugin Function’s Variable in Theme Template [duplicate]
- WordPress theme header.php should I add title meta?
- Help with Core Mods
- Problems with cart and pages on _s theme
- Local variable name in setup_postdata()
- Creating a Single Page Theme correctly
- Custom post type query with pagination doesn’t work
- Fatal error: Class WP_Customize_Image_Control not found
- Child theme menu not appearing in Twenty Seventeen
- Edit Product Archive design for Woo theme
- How do I remove header/page-title image in farvis theme? [closed]
- how to edit woocommerce checkout page
- Which theme PHP file should be edited in order to change Posts appearance
- Necessary css classes to be included in theme stylesheet
- How to link post image to post link?
- How to hide blog by id wordpress multisite listing
- get_the_excerpt() removes all p tags in page!
- jQuery conflict in WordPress, works fine in HTML
- Including some variables in function.php and echo them is several place of theme is not working
- How to override wordpress native options with theme options
- How to migrate the menu from the site on my own theme in WordPress?
- Why is including all your files within a theme folder important?
- Change default options on attachment page
- FitVid not working for iframes on particular theme install
- How to create multiple sidebar areas with a forloop and register_sidebars?
- Make theme editor to show all theme’s files
- can’t add EVENT LISTENER to a element
- add_action works outside condition but not inside it
- Bootstrap isn’t called into my WordPress theme
- Jquery Ui Tabs not working
- Adding a new layout for genesis
- Which function(s) to build a paged HTML table
- Bootstrap 4 mobile menu not working for WordPress Development
- Configuring static page with add_rewrite_rule gives 404 after navigating to Permalinks admin panel
- How do I send out an update for my custom wordpress theme?
- custom wordpress theme blog page always not showing the last two pages of the articles
- Cart button not working on mobile version [closed]