I have a custom post type "treatment", under this CPT the taxonomy "treatment_category" which forntend slug is "category"

right now the URL for category displaying as follows.


Just want to remove the slug "category" and display as


also the post URLs like this


also want to change this to as below by removing "treatment"


is this possible.


1 Answer 1


yes, possible to achieve the URL structure you desire by modifying the permalink structure for your custom post type and taxonomy.

Firslty flush the rewrite rules by visiting the permalink settings page in your Wp admin area Settings > Permalinks and clicking Save Changes. This will regenerate the rewrite rules and apply your custom permalink structure.

After adding the below code in your current active theme functions.php file or your custom plugin.

Remove treatment_category from the category URL

add_action('init', 'custom_taxonomy_rewrite_rule');
function custom_taxonomy_rewrite_rule() {
    $taxonomy_slug = 'treatment_category'; // Change this to your taxonomy slug
    $taxonomy = get_taxonomy($taxonomy_slug);
    $taxonomy->rewrite['slug'] = ''; // Set the slug to empty to remove "category" from the URL

Remove treatment from the post URL

add_action('init', 'custom_post_type_rewrite_rule');
function custom_post_type_rewrite_rule() {
    $post_type_slug = 'treatment'; // Change this to your custom post type slug
    $post_type = get_post_type_object($post_type_slug);
    $post_type->rewrite['slug'] = ''; // Set the slug to empty to remove "treatment" from the URL

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.