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?

1 Answer
1

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.

Leave a Reply

Your email address will not be published. Required fields are marked *