0

I already know that you can add /blog/ on the custom structure under permalink settings. However, when I do that, it also applies to the permalink of my portfolio project types like this:

domain.com/blog/project-type/%project_type%/

How do I make the /blog/ disappear on the project type but not on the post permalinks.

1
  • Did you register the portfolio type yourself, or is it from a plugin? – Jacob Peattie Mar 12 at 12:07
-1

You can use the "post_link" filter with a conditional to check the post type to modify the single posts.

For example:

add_filter( 'post_link', function($post_link, $id){
  $post = get_post( $id );
  if( is_object( $post ) && 'post' === $post->post_type ) {
    return home_url( '/blog/' . $post->post_name );
  }
  return $post_link;
}, 10, 2 );

You would also need to modify the rewrite rules using the 'generate_rewrite_rules' filter.

Edit: This question has already been answered with a better code example here: Custom permalink structure with a prefix just for posts

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.