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 need to remove the parent slug in the permalink of a child post. The child post is of a different cpt than the parent post. So I get:

example.com/parentcpt/parent-post-name/child-post-name //which results to a 404.

I need




Switching between permalink structures doesnt help either. Ive tried a number of plugins but they dont solve. Adding the following doesnt help:

'rewrite' => array('slug' => false, 'with_front' => false)// register_post_type function

Someone help please ... :)

share|improve this question

I was able to solve this problem by adding the code below under my theme/functions.php file. (My custom post type slug is 'news')

            function df_custom_post_type_link( $post_link, $id = 0 ) {  
                $post = get_post($id);  
                if ( is_wp_error($post) || 'news' != $post->post_type || empty($post->post_name) )  
                    return $post_link;  
                return home_url(user_trailingslashit( "$post->post_name" ));  
            add_filter( 'post_type_link', 'df_custom_post_type_link' , 10, 2 );
            function df_custom_rewrite_rule() {
                add_rewrite_rule('(.*?)$', 'index.php?news=$matches[1]', 'top');
            add_action('init', 'df_custom_rewrite_rule');
share|improve this answer
Is there a way to alter this for multiple custom post types? (So more than just 'news')? – tmyie Dec 12 '13 at 11:01

Your Answer


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.