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/blog/project-type/%project_type%/
How do I make the /blog/
disappear on the project type but not on the post permalinks.
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/blog/project-type/%project_type%/
How do I make the /blog/
disappear on the project type but not on the post permalinks.
- Did you register the portfolio type yourself, or is it from a plugin? – Jacob Peattie Commented Mar 12, 2021 at 12:07
1 Answer
Reset to default -1You 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