This code will check to ensure that the theme_location
is header
. Also, menu
is the parameter where the desired WordPress Nav menu is specified. menu_id
is the HTML ID that is applied to the <ul>
element which forms the menu. Docs on the arguments for wp_nav_menu()
can be found here.
add_filter( 'wp_nav_menu_args', 'bb_wp_nav_menu_args' );
function bb_wp_nav_menu_args( $args ) {
if ( 'header' !== $args['theme_location'] ) {
return $args;
}
if ( is_single( '123' ) ) {
$args['menu'] = '12'; // Replace with desired menu ID, slug, or name
} else if ( is_single( '116' ) ) {
$args['menu'] = '12'; // Replace with desired menu ID, slug, or name
} else if ( is_category( '15' ) ) {
$args['menu'] = '12'; // Replace with desired menu ID, slug, or name
}
return $args;
}