admin管理员组文章数量:1421943
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.
本文标签: Assign a different menu depending on custom taxonomy
版权声明:本文标题:Assign a different menu depending on custom taxonomy 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745360911a2655288.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论