使用has_nav_menu(), 和测试theme_location, 而不是menu_id:
<?php
if ( has_nav_menu( $theme_location ) ) {
// User has assigned menu to this location;
// output it
wp_nav_menu( array(
\'theme_location\' => $theme_location,
\'menu_class\' => \'nav\',
\'container\' => \'\'
) );
}
?>
您可以通过添加
else 条款
EDIT
您需要更换
$theme_location 使用您的实际
theme_location:
<?php
if ( has_nav_menu( \'main_nav\' ) ) {
// User has assigned menu to this location;
// output it
wp_nav_menu( array(
\'theme_location\' => \'main_nav\',
\'menu_class\' => \'nav\',
\'container\' => \'\'
) );
}
?>