I have created a custom post type 'Shop' with a custom taxonomy for Shop Categories
For my shop category archive pages I want the URL structure to be:
example.com/shop/tech/ (instead of example.com/shop/category/tech/)
And I want Shop posts to be example.com/shop/shop-post-title-example
I have tried the code below and saved permalinks but when I visit a Shop post it shows a 404 error.
Is it possible to remove the category base without errors?
// Custom Post Type : Shop
function my_custom_post_shop() {
$labels = array(
'name' => _x( 'Shop', 'post type general name' ),
'singular_name' => _x( 'Product', 'post type singular name' ),
'add_new' => _x( 'Add New', 'Product' ),
'add_new_item' => __( 'Add New' ),
'edit_item' => __( 'Edit' ),
'new_item' => __( 'New Product' ),
'all_items' => __( 'All Products' ),
'view_item' => __( 'View Product' ),
'search_items' => __( 'Search Products' ),
'not_found' => __( 'No projects found' ),
'not_found_in_trash' => __( 'No projects found in the Trash' ),
'menu_name' => 'Shop'
);
$args = array(
'label' => __( 'Shop' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'comments', 'revisions', 'custom-fields', 'thumbnail', ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'rewrite' => array( 'slug' => 'shop' ),
'has_archive' => 'shop',
);
register_post_type( 'shop', $args );
}
add_action( 'init', 'my_custom_post_shop' );
// Shop Categories
function my_taxonomies_shop() {
$labels = array(
'name' => _x( 'Shop Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Shop Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category' ),
'menu_name' => __( 'Shop Categories' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'show_admin_column' => true,
'rewrite' => array( 'slug' => 'shop'),
);
register_taxonomy( 'shop_category', 'shop', $args );
}
add_action( 'init', 'my_taxonomies_shop', 0 );