Blog Archives

Custom Taxonomy permalink

Add this coding into theme functions.php.
Change the permalink by replacing the custom_taxonomy_name to your desired custom taxonomy name.
Also Change default_custom_taxonomy_name with the default custom taxonomy term.
add_filter('post_link', 'custom_taxonomy_name_permalink', 10, 3);
add_filter('post_type_link', 'custom_taxonomy_name_permalink', 10, 3);
function custom_taxonomy_name_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, '%custom_taxonomy_name%') === FALSE) return $permalink;
$post = get_post($post_id);
if (!$post) return $permalink;
$terms = wp_get_object_terms($post->ID, 'custom_taxonomy_name');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;
else $taxonomy_slug = 'default_custom_taxonomy_name';
return str_replace('%custom_taxonomy_name%', $taxonomy_slug, $permalink);
}

then set custom Permalink structure as shown below
Replace custom_taxonomy_name by your custom taxonomy name.
/%custom_taxonomy_name%/%postname%/

Design a site like this with WordPress.com
Get started