Is it possible to remove alias from custom post type? Let me tell a bit more. For instance, I’ve created a post type, name “Book”. So URL will be domain.com/book/post-title
or domain.com/?post_type=book&p=528.
I want the URL as domain.com/post-title.
Is it possible?
In short – you cannot, or at least should not.
www.domain.com/post-title
is interpreted as post (if your structure is %postname%
) and/or a page – and WordPress is set to deal with them as such, including any conflicts.
You can do the following:
add_action('init','wpse0845_add_rule');
function wpse0845_add_rule(){
add_rewrite_rule("([^/]+)/?",'index.php?book=$matches[1]','top');
}
(and then flush rewrite rules, once).
However, you’ll notice that now your pages (and depending on your structure, posts too) give a 404.