Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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: I want How can I do that?

share|improve this question

1 Answer 1

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.