WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created a custom post type Track and I want the posts url to be exactly like a normal post url. Now it adds an extra "track" in the url ex: www.site.com/track/title. I want www.site.com/title. How can I do that?

share|improve this question

You need to add a custom rewrite rule in functions.php:

function your_cpt_rewrite_rule() {
    add_rewrite_rule('(.*?)$', 'index.php?your_cpt=$matches[1]', 'top');
add_action('after_theme_setup', 'your_cpt_rewrite_rule');
share|improve this answer
Your regex is wrong (no leading ^), and this is a terrible idea. You're going to prevent WordPress from matching any other things with this. In other words, this will probably 404 every page -- except for the rare instances where .*? actually matches a custom post type's slug. – chrisguitarguy Jul 22 '13 at 3:11

Your Answer


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