Programmatically assigning a menu to a location
-
Hi,
I’ve been using wordpress for a while now, but just starting to build my own theme and plugins. I’m creating my own site using a child theme and a custom installer and am having a couple of problems if anyone can help.
I would like to programmatically assign a menu to a menu location when WordPress installs (Either in the custom install file or through a theme file). I am struggling to find the relevant code, and location for that code
I have tried to figure out using set_theme_mod, but I cannot figure out the syntax. Looking at the database after manually created the assignment didn’t help either!
I know I’m looking at ‘nav_menu_locations’ but I’m not sure how to write the set_theme_mod function, It takes 2 arguments, But I can’t figure out how to write the value. I figure it looks something likeset_theme_mod (‘nav_menu_locations’, ‘main_nav=>main’)
(The location is called ‘main_nav’, the Menu is called ‘main’,)But I’ve tried several combinations and none works
Also, where abouts should I put this code? I tried it in the install.php file after switching themes programmatically, but I think it should go in the theme, but where? which file is run when the theme is installing?
Many thanks
John
The topic ‘Programmatically assigning a menu to a location’ is closed to new replies.