主题激活后,WordPress自定义菜单自动激活

I am new developer. I have created a custom menu in wp dashboard. Now I want when my theme is active then my custom menu is also active automatically by my custom location. How can I do that?

$menu_header = get_term_by('name', 'Menu 1', 'nav_menu');
$menu_header_id = $menu_header->term_id;

//Get all locations (including the one we just created above)
$locations = get_theme_mod('nav_menu_locations');

//set the menu to the new location and save into database
$locations['Primary'] = $menu_header_id;
$set_theme_mod = set_theme_mod( 'nav_menu_locations', $locations );