事实上,我认为你需要隐藏或显示菜单项的基础上"User Role". 因此,这里一个可能的解决方案是为每个角色创建菜单,并根据条件显示它们"User Role". 这是代码-
function the_dramatist_menu_change( $args = \'\' ) {
$current_user = wp_get_current_user();
if( in_array(\'your-user-role\', $current_user->roles) ) {
$args[\'menu\'] = \'Menu 1\'; // Menu name as string
} else {
$args[\'menu\'] = \'Menu 2\'; // Menu name as string
}
// Add more else if condition based on your user roles.
return $args;
}
add_filter( \'wp_nav_menu_args\', \'the_dramatist_menu_change\' );