i have one cpt Anime and it has post_type taxonomy with term anime and animation

anime(cpt): (site domain)/anime/post title

And my url structure are like: (site domain)/anime/post title but i wanna this kind of urls:

     |-(tax)Anime: (site domain)/anime/post title
     |-(tax)Animation: (site domain)/animation/post title

i really don't know how to build it.

after alot of try and error i find my solution:

add_filter('post_type_link', 'events_permalink_structure', 10, 4);
function events_permalink_structure($post_link, $post, $leavename, $sample){

$types=wp_get_object_terms( $post->ID, 'post_types' );
if (( 'animation' == $types[0]->slug )or ( 'comic' == $types[0]->slug )) {
    $post_link = str_replace( array('/anime/','/manga/'), '/'.$types[0]->slug.'/', $post_link );
return $post_link;

 function animation_init() {
 global $wp,$wp_rewrite,$wp_query;
 $wp_rewrite->add_rule('^comic/([^/]*)/?$','index.php?post_type=manga&name=$matches[1]', 'top');
  $wp_rewrite->add_rule('^animation/([^/]*)/?$','index.php?post_type=animes&name=$matches[1]', 'top');
  // Once you get working, remove this next line

but now i face a new problem, my old urls still working like:

http://animup.net/anime/the-advantures-of-brer-rabbit/ (should redirect to) http://animup.net/animation/the-advantures-of-brer-rabbit/

1 Answer 1


The old permalinks still work because the rewrite rules that support those permalinks still exist. When you register a post type, setting the rewrite argument generates the rules to resolve incoming requests. Rather than adding new rules in addition to the originals, just alter the original post type registration.

  • i don't wanna redirect all urls, i only wanna redirect posts with animation taxonomy term. Commented Mar 18, 2015 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.