How to display conditional menus with Twenty-twenty two theme?

With earlier versions of default Wordpress themes I was able to display an alternative main menu depending on the category of the given page or post, using this filter in my functions.php:

( In this example we have German and French categories that display menus named German or French. All other categories display the menu named English. )

function my_conditional_menus( $args = '' ) {
  if (in_category('german')) { 
    $args['menu'] = 'german';
  } elseif (in_category('french')) {
    $args['menu'] = 'french';
  } else {
    $args['menu'] = 'english';
  }
  return $args;
}
add_filter( 'wp_nav_menu_args', 'my_conditional_menus' );

Unfortunately I noticed this solution does not work with the Twenty Twenty-Two theme.

How could I make it useable for this theme?

Topic navigation functions conditional-content menus Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.