A site is using “child1” named child theme. When this site switches to other child theme named “child2”, their widgets are moving too but theme locations are not moving. How can i auto assign menus to theme locations on theme activation?
I found this solution from http://wordpress.org/support/topic/how-to-assign-a-wordpress-3-menu-to-primary-location-programmatically
$theme = get_current_theme();
$mods = get_option("mods_$theme");
$key = key($mods['nav_menu_locations']);
$mods['nav_menu_locations'][$key] = $menu_id;
update_option("mods_$theme", $mods);
Is there any better wordpress way to fix this?
(Related trac topic: http://core.trac.wordpress.org/ticket/18720 )
Well,
I wrote a solution so writing it here:
I know you had this issue long time ago but since this site popped up with the first few, I thought to share my solution in case someone needs it.
Either in your setup file or in your general
functions.php
, update and include the following code: