skip to Main Content

I have a WP site where there are 3 taxonomies, the main categories, companies and regions. I’m looking for them to all use the same permalink structure like:

site.com/{category-slug} site.com/{company-slug} site.com/{region-slug}

Is there a way to make this work and rewrite the urls within functions.php? I’ve tried a couple of methods, but sometimes they work, but then the main pages 404.

Thanks in advance

2

Answers


  1. Have you tried this?

        function change_custom_taxonomy() {
        $custom_category_args = get_taxonomy( 'custom_category_slug' );
        $custom_category_args->show_admin_column = true;
        $custom_category_args->rewrite['slug'] = 'category_slug_which_you_want';
        $custom_category_args->rewrite['with_front'] = false;
        register_taxonomy( 'custom_category_slug', 'category_slug_which_you_want', (array) $custom_category_args );
    }
    add_action( 'init', 'change_custom_taxonomy', 11 );
    
    Login or Signup to reply.
  2. To achieve this, you can indeed use the functions.php file to rewrite URLs.

    Start by adding custom rewrite rules and flushing the rewrite rules using the ‘flush_rewrite_rules()’ function. Additionally, ensure that your custom rewrite rules don’t conflict with existing ones.

    Keep in mind that troubleshooting permalink issues can sometimes lead to temporary 404 errors, but your determination to find a solution is key.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search