When we create a custome post taxonomy in wordpress, sometimes we faced confliction with same slug of page and taxonomy.
At that time we change the name of our page or taxonomy for avoid this confliction.
But here is simple solution for this problem. You don’t need to change the name of page or taxonomy.
This solution is very useful when your taxonomy name is same as your page or post name.
See below example, Here taxonomy name is brands. Supposed you have already a page with brands name then follow the below code.
'rewrite' => array( 'slug' => 'brands' ), 'has_archive' => 'brands/',
Here is full code of how to create a taxonomy, please have a look.
register_post_type( 'Brands', array( 'labels' => array( 'name' => __('Brands', 'gdlr-AboutUs'), 'singular_name' => __('Brands', 'gdlr-AboutUs'), 'add_new' => __('Add New', 'gdlr-AboutUs'), 'add_new_item' => __('Add New Brands', 'gdlr-AboutUs'), 'edit_item' => __('Edit Brands', 'gdlr-AboutUs'), 'new_item' => __('New Brands', 'gdlr-AboutUs'), 'all_items' => __('All Brands', 'gdlr-AboutUs'), 'view_item' => __('View Brands', 'gdlr-AboutUs'), 'search_items' => __('Search Brands', 'gdlr-AboutUs'), 'not_found' => __('No Brands found', 'gdlr-AboutUs'), 'not_found_in_trash' => __('No Brands found in Trash', 'gdlr-AboutUs'), 'parent_item_colon' => '', 'menu_name' => __('Brands', 'gdlr-AboutUs') ), 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'brands' ), 'has_archive' => 'brands/', 'capability_type' => 'post', 'hierarchical' => false, 'menu_position' => 5, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'custom-fields' ) ) ); // create Brands categories register_taxonomy( 'Brands_category', array("Brands"), array( 'hierarchical' => true, 'show_admin_column' => true, 'label' => __('Brands Category', 'gdlr-Brands'), 'singular_label' => __('Brands Category', 'gdlr-Brands'), 'rewrite' => array( 'slug' => $portfolio_category_slug ))); register_taxonomy_for_object_type('Brands_category', 'Brands');
Don’t forgot to save the permalink setting in wordpress admin otherwise you did not get the effect of this solution.
Thanks !! 🙂