Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
I was successful using a combination of some tricks. Rewrite rules in functions and htaccess, and some special configuration in 'rewrite' => array( 'slug' => ... Anyway, thanks Stephen for your answer. –  Enthusiast May 2 '12 at 13:06
    
Tanmoy, could you perhaps supply the rest of that solution? –  Zach L Jul 2 '12 at 5:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.