I'm editing the default WordPress "post" custom post type, to add a "news" prefix before the single posts. I've used the register_post_type_args hook to add my args. It does work however it doesn't redirect the default permalink.

For example the post;

.com/news/hello-world Valid

.com/hello-world Valid

I don't want the 2nd example to valid and rewrite it to have the permalink prefix news.

function custom_post_prefix( $args, $post_type ) {
  if( 'post' == $post_type ) {
    $args['rewrite']['slug'] = 'news';
  return $args;
add_filter( 'register_post_type_args', 'custom_post_prefix', 10, 2 );

*Note I have a number of custom post types added so using the admin interface is not usable in this case.

New contributor
Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • You can just do this in Settings > Permalinks. – Jacob Peattie Apr 8 at 14:54
  • @JacobPeattie Please read the full question, this is not possible within Settings > Permalinks because it will add the prefix to all my other custom post types. – Sam Apr 8 at 15:35
  • Set with_front to false on those post types. – Jacob Peattie Apr 8 at 16:10

Your Answer

Sam is a new contributor. Be nice, and check out our Code of Conduct.

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

Browse other questions tagged or ask your own question.