Rewrite url for custom post type and custom taxomonies in wordpress
Rewrite url for custom post type and custom taxomonies in wordpress
I have custom post type and custom taxonomies.
Currently I am using custom category in my menus and url of that is.
https://example.com/customposttypeslug/categories1
https://example.com/customposttypeslug/categories2
https://example.com/customposttypeslug/categories3
So i want to change this to as below
https://example.com/categories1
https://example.com/categories2
https://example.com/categories3
I have gone through many articles on stack and google but i didnt find how to remove customposttype slug from url for custom post type.
Here is the code for creating custom post type and taxonomies
add_action('init', 'shopify_theme_app_cpt');
function shopify_theme_app_cpt() {
register_post_type('apps', array(
'labels' => array(
'name' => 'Shopify Themes & Apps',
'singular_name' => 'Shopify Theme & App',
),
'description' => 'Add shopify themes and apps for showing a customer.',
'public' => true,
'menu_position' => 20,
'supports' => array('title', 'editor', 'custom-fields','thumbnail'),
'rewrite' => array( 'slug' => 'apps', 'with_front' => false ),
));
}
// set up labels
$labels = array(
'name' => 'shopify Categories',
'singular_name' => 'shopify Category',
'search_items' => 'Search shopify Categories',
'all_items' => 'All shopify Categories',
'edit_item' => 'Edit shopify Category',
'update_item' => 'Update shopify Category',
'add_new_item' => 'Add New shopify Category',
'new_item_name' => 'New shopify Category',
'menu_name' => 'shopify Categories'
);
// register taxonomy
register_taxonomy( 'shopify', 'apps', array(
'hierarchical' => true,
'labels' => $labels,
'query_var' => true,
'show_admin_column' => true
) );
The url is displaying like this :-
https://example.com/shopify/apps
I want to remove shopify from the url.
hi kaddath, I have added my code.Please can you check it where i am doing wrong
– Deepak Lakhara
Jul 2 at 10:17
1 Answer
1
Try this, it might help. for more
'rewrite' => array('slug' => 'customposttypeslug','with_front' => false),
'rewrite' => array('slug' => 'customposttypeslug','with_front' => false),
*****just make sure that, after updating the code, you flush the rewrite rules by visiting Settings > Permalinks. Otherwise, you'll still see the old links.*****
It worked for me to remove customposttype slug.But how can i remove the taxonomy slug.
– Deepak Lakhara
Jul 2 at 11:37
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can you edit your question to include how do you register your custom post type, one example of taxonomy, and if possible what you have already tried and how didn't it work or gave an unexpected result? Is there something useful for you for example in this post?
– Kaddath
Jul 2 at 8:50