I was wondering how i can remove the prefix from the slugs of custom post types using htaccess rules or any other appropriate method.
Currently my custom post types look like this:
http://www.domain.com/os_estate/5-bedroom-property-for-sale
and i would simply like this to be:
http://www.domain.com/5-bedroom-property-for-sale
I was able to achieve this via a plugin but it significantly added to the page load time..
My common settings in Permalinks is set to “Post Name”
There is a simpler and lighter solution:
First: set the slug argument for your custom post type to ‘/’ when registering the post type:
Second: in
preg_get_posts()
action hook include your post type in the query when only the$query->query['name']
is present:Third: I’ve found that in some situations there are conflicts with pages and single posts. I’ve been able to avoid this conflict by checking if a page with the request name exists and overriding the query conditionals but I’m not sure if more conflict can happens:
IMPORTANT: You need to flush the rewrite rules. You can do it by viviting the permalink options page in the admin area. This is needed because we are registering a new rewrite rule, so the current rewrite rules stored in the database must be regenerated.
// Well then, first use a function to mention your custom post types.
// Then, filtering the request.
// And next filter all the desired post types link.
EDIT: fixed errors, adding this line due to edit 6 chars minimum requirement
I think that you just need to put rewrite rule in your code in place where you register post type.
Just place this code
after the $labels array();
and before $args = array();