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

时间:2018-09-23 06:25:39

标签: php wordpress menu wordpress-theming

我是新开发人员。我在wp仪表板中创建了一个自定义菜单。现在我要当我的主题处于活动状态时,我的自定义菜单也会根据我的自定义位置自动处于活动状态。我该怎么办?

$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 );

0 个答案:

没有答案
相关问题