您可以使用wp_nav_menu_objects
或wp_nav_menu_items
钩子来添加过滤函数。
function my_hide_menu_items($objects) {
if ( is_admin() ) return $objects;
foreach ( $objects as $k=>$object ) {
if ( YOUR CONDITION ) { // if $object shouldn\'t be displayed
unset($objects[$k]);
}
}
return $objects;
}
add_filter(\'wp_nav_menu_objects\', \'my_hide_menu_items\', 10, 2);