I have a Custom Post Type named News that has a URL structure like this…
domain.com/news/news-post-name
I have also added a Custom Tag Taxonomy for my News Post Type.
Here is my Re-write settings for it…
$news_posts_tag_args = array(
'rewrite' => array(
'slug' => 'news-tag',
'with_front' => false,
'hierarchical' => true,
)
);
This makes mt News Tag have a URL like this…
domain.com/news-tag/news-TAG-name
However I would like my it to appear that I have tag
under my News Post Type
So that it will instead be like this…
domain.com/news/tag/news-TAG-name
I am able to achieve this by using the Re-write code below…
function custom_taxonomies_rewrite(){
add_rewrite_rule('^news/tag/([^/]*)/?','index.php?news_tag=$matches[1]','top');
}
add_action('init','custom_taxonomies_rewrite');
So far everything works great but I then have to make sure to edit anything that links to the News Tag Taxonomy to make sure it uses my new custom URL structure for that Taxonomy.
So I am hoping someone can help me with the next step of my process by helping to to hook into Tag links so maybe I can change the links more easily?
If anyone else is looking for this in the future, the result I came up with is this one…
It will run code on Taxonomy Links. I still need to add in functionality to work with more then 1 custom taxonomy but this is a good start and works for 1