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;
}