我知道你很久以前就有过这个问题,但由于这个网站出现了前几个问题,我想分享我的解决方案,以防有人需要它。
在安装文件或常规文件中functions.php
, 更新并包含以下代码:
// This theme uses wp_nav_menu() in one location.
register_nav_menu( \'primary\', __( \'Primary Menu\', \'theme-slug\' ) );
// get \'your_custom_menu\' id to assign it to the primary menu location created
$menu_header = get_term_by(\'name\', \'your_custom_menu\', \'nav_menu\');
$menu_header_id = $menu_header->term_id;
// if menu not found, create a new one
if($menu_header_id == 0) {
$menu_header_id = wp_create_nav_menu(\'your_custom_menu\');
}
//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( \'nav_menu_locations\', $locations );