您应该能够有条件地使菜单短路return
通过将此代码添加到主题来删除空字符串functions.php
:
add_filter( \'pre_wp_nav_menu\', \'wpse_210095\');
function wpse_210095($menu) {
if (is_home()) {
$menu = \'\';
}
return $menu;
}
You can see in the Core where this logic executes:
260 $nav_menu = apply_filters( \'pre_wp_nav_menu\', null, $args );
261
262 if ( null !== $nav_menu ) {
263 if ( $args->echo ) {
264 echo $nav_menu;
265 return;
266 }
267
268 return $nav_menu;
269 }