3

My company policy is to prepend "/blog/" to our Post slugs. Normally our SEO team will do this via the Custom Permalinks setting (/blog/%postname%), but this has the side effect of pre-pending /blog/ to other Custom Post Types as well.

I know I can set the with_front attribute to false when registering Custom Post Types to avoid this issue, but it's quite a pain when Themes add their own Custom Post Types, or if we inherit sites from other developers.

Has anyone else run into this issue, and if so, how do you get around it?

2

Use the register_post_type_args filter to alter post types registered by code you don't control.

You can set it for a specific type:

add_filter( 'register_post_type_args', 'wpd_change_post_type_args', 10, 2 );
function wpd_change_post_type_args( $args, $post_type ){
    if( 'turnips' == $post_type ){
        $args['rewrite']['with_front'] = false;
    }
    return $args;
}

Or remove that $post_type check to change it for all custom types.

1
  • This looks like it will work, the problem is I don't want to be risky and ever accidentally remove 'with_front' from custom post types in the future that DO need the Custom Permalink structure. Ideally there would be an option in WP's dashboard UI or a plugin that only affects default Posts permalinks. But oh well, your answer is super helpful and does answer my question – user3183717 Jun 6 '18 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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