admin管理员组文章数量:1320821
I have created a custom post type named video and a custom taxonomy for video as video_category. I have created a page template with the name taxonomy-video_category.php. So that the categories of the videos can be viewed on the URL mysite/video_category/{category_name}.
I need to change this URL to mysite/videos/category/{category_name}. I tried the plugin Custom Permalinks. But it does not allow me to change this URL on edit of the taxonomy video_category.
I want to do this preferably without the use of plugins. How do I do this?
I have created a custom post type named video and a custom taxonomy for video as video_category. I have created a page template with the name taxonomy-video_category.php. So that the categories of the videos can be viewed on the URL mysite/video_category/{category_name}.
I need to change this URL to mysite/videos/category/{category_name}. I tried the plugin Custom Permalinks. But it does not allow me to change this URL on edit of the taxonomy video_category.
I want to do this preferably without the use of plugins. How do I do this?
Share Improve this question asked Oct 9, 2020 at 9:38 Saeesh TendulkarSaeesh Tendulkar 1531 silver badge7 bronze badges1 Answer
Reset to default 2You can use the rewrite
parameter to customize the taxonomy permalinks.
Here's an example which links the taxonomy to the default post
post type:
register_taxonomy( 'video_category', 'post', [
'public' => true,
'rewrite' => [
'slug' => 'videos/category',
],
// ... your other parameters ..
] );
Don't forget to flush the rewrite rules — just visit the permalink settings admin page.
And if the taxonomy is being registered by a plugin and (just in case) it doesn't allow changing the rewrite slug, there's a filter hook you can use to change the slug programmatically: register_taxonomy_args
. Here's a simplified example:
add_filter( 'register_taxonomy_args', 'my_register_taxonomy_args', 10, 2 );
function my_register_taxonomy_args( $args, $taxonomy ) {
if ( 'video_category' === $taxonomy ) {
$args['rewrite'] = (array) $args['rewrite'];
$args['rewrite']['slug'] = 'videos/category';
}
return $args;
}
本文标签: Change custom taxonomy archive permalink
版权声明:本文标题:Change custom taxonomy archive permalink 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742072651a2419220.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论