Remove Post Type Slug from URLs
I’ve been asked about how to do it probably a million times. The question is how to make the URLs of your custom post types (or WooCommerce products) to look like Pages.
For example how to have example.com/t-shirt/
instead of example.com/product/t-shirt/
.
In this tutorial I am going to provide you a complete guide! As an example we are going to remove /product/ from WooCommerce product URLs. But before we begin I would like to warn you that you have to avoid it if possible, because it may slows down the overall performance of your website and you have to be extra-careful when assigning a specific slug for your posts.
Permalink post_type structure with taxonomy slug in it
Let’s look at the simple example of a eshop on WordPress.
The shop has custom post type product
and category for products product_cat
. By default product links looks like
How to Change URL of a custom post / page / category / tag in theme functions.php. Capitalize URL.
If you read this post, you should know something about WP_Rewrite class. It allows you to change WordPress permalinks rewrite reules, change the structure of them.
In this post I won’t use WP_Rewrite, I just want to show you another way of