I've been googling, tinkering around and investigating/testing settings however nothing seems to work so please bear with me on this and please help me if you can. Thanks so much!

I have the custom taxonomy called "location" created via the CPT UI plugin - below is the code used by CPT UI plugin to register new taxonomy "location".

function cptui_register_my_taxes_location() {

     * Taxonomy: Locations.

    $args = array(
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => true,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => array( 'slug' => 'location', 'with_front' => true, ),
        "show_admin_column" => true,
        "show_in_rest" => true,
        "rest_base" => "location",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "show_in_quick_edit" => true,
    register_taxonomy( "location", array( "post", "blog" ), $args );
add_action( 'init', 'cptui_register_my_taxes_location' );

Now here is the issue I'm having trouble finding the solution for: is there a way to assign a set of menu depending on what taxonomy of the page is?

Ideally, I'll create a set of menu under Appearance > Menus and name it "Test Menu" and then assign it to a specific taxonomy term - is there a wordpress code (function) that we can all use wherein we'll set the TAXONOMY name and the matching MENU name?

Thanks so much guys in advance for your help!

1 Answer 1


I think the way to do this is:

  1. Set up your menu in Appearance > Menus as you mentioned;
  2. In your theme's header.php (or wherever you find the wp_nav_menu() code that displays your current menu), set up a WordPress conditional to check if the page being visited is a location taxonomy archive, and display different menus based on that. For instance:

    if (is_tax('location')) { wp_nav_menu( array($args = array( 'menu' => 'test-menu', // your menu slug here ) ); } else { wp_nav_menu(); // your original menu code here }

See the Conditionals page in the WordPress codex for all the options you could use here, there are many.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.