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!
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!
Share Improve this question asked Jun 28, 2019 at 16:11 BacorritoBacorrito 54 bronze badges1 Answer
Reset to default 0I think the way to do this is:
- Set up your menu in Appearance > Menus as you mentioned;
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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745360911a4624353.html
评论列表(0条)