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
Related Posts:
- Where is the old post permalink slug stored?
- How to Check if a Page Exists by URL?
- Post slugs and images cannot have same name?
- Change permalinks for post type ‘post’ only
- Pretty URL with add_query_var
- get_permalink returns default link
- Group Posts by First Letter of Title
- how to get permalink using sql
- Why can posts never have a number as the link?
- How to allow slashes in single posts when i click in the edit permalink button
- Post custom permalink results in 404 for archive page
- Some posts returning 404 instead of displaying post
- Custom post type single (permalink) throws a 404 error
- Link for the page archive for posts, like using custom post types with get_post_type_archive_link
- Random post permalink
- What Defines What Category A Post Picks (if in multiple)
- get_permalink executes link without https
- Custom post type permalinks breaking due to 3.1 bug fix
- How can a guest view the “Pending Review” Post?
- Create pretty permalink for a post knowing the permalink structure
- Changing my permalink structure – will new layout conflict with existing page?
- Link post permalinks to subdirectory /post
- change default post archive page link
- Remove permalink from images when inserting into post
- Remove the Edit button in posts for permalinks on certain user roles? WP 3.3
- Dynamically generate child-URLs for posts or custom posts
- Adding parent pages to posts
- Plain permalinks not working!
- Changing Permalinks for Default Post type to reflect navigation
- How should I add links to other pages/posts from my post?
- WordPress not opening posts with only numbers if permalink is post_name
- Using permalinks, category slugs, and tag slugs
- Problem with permalink routing?
- Move first half of posts to one parent page, second half to the other page
- How to check a post exist when the permalink has post id in it?
- How to do set post permalinks using 6 digit random unique function?
- Switch to page template when using post permalink
- Trying to use AngularJS with WordPress without any API
- How to handle broken links created by permalink/slug changes?
- Visting slug for ‘post’ post type shows 404 not archive?
- Any way for get_next_post() to use the actual post order instead of publish order?
- how do i add posts-page slug before posts slug in permalinks
- Permalink doesn’t get displayed in Twitter button (Local WordPress problem?)
- Retrieve post ID from “querying” URL
- When changing pages to posts, how do you set up 301 redirects for the page URLs?
- custom word in custom permalink structure
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts
- Unabled to Change Permalinks – Even Using the “Edit” (Resets to Original Permalink on “Update”)
- When WP_Query only returns 1 post, how do I automatically redirect to that post?
- Internal linking to posts permalink fail because of spaces and stripe at postname
- Link post images to post
- Problems with WordPress in subfolder, posts show a blank page
- how to create a sub section in posts
- Standalone form does not post to the url when form fields are populated (otherwise it does)
- Rewriting blog permalinks
- Change permalinks for posts & for custom post types
- Permalink Short code showing unnecessary link text inside the loop
- My post permalinks are redirecting to the post archive page for some reason?
- How can I make a post sub link?
- How do you change the permalink for posts for a single category?
- How to set the post permalink using the WordPress REST API?
- Does having category name in permalinks affect SEO when having a post in multiple categories?
- unable to display two post per page in wordpress front-page.php
- How to 301 redirect from url with post id to permalink with post name (slug)?
- Prevent Archive URLs
- Custom Post Types and Broken Permalinks
- Custom permalink for wordpress page / post
- Permalink structure for two seperate blogs
- My post permalinks are always the same
- How to give priority to page than to posts permalink structure?
- Append a random string to a post permalink
- Precedence of page permalinks over woocommerce product category links?
- Fixing the WP Post Object for Custom Route
- All my posts don’t show, only the headline is displayed on the homepage
- How to change post template via url?
- Posts in Page – How to customize the URL?
- Is there a way to change the complete URL of the blog post for a redirecting tracking link?
- WordPress with static posts page and custom permalink structure doesn’t find posts with numeric permalinks
- Use a custom post URL that is outside the blog root directory
- Can’t seem to replicate permalink structure for localhost development site
- WordPress rewrite url help needed
- Permalink of some posts change
- My posts section for logged in user
- Change link to permalink inside post content
- How to mix pages and sub-categories in a url
- Changing permalink of custom category
- TCPDF and permalinks
- Overwrite URL on blog posts
- WordPress sub-posts and permalinks
- How to display subcategory articles in the category view?
- Change posts URL [duplicate]
- 301 Redirecting posts without %postid% (just %post_name%) in permalink to ones with %post_name%_%postid%
- Permalink remain the same on each page
- Read more link not working [closed]
- After the local installation of an old WP website I can see the homepage but I can’t access to the articles, why?
- How can I fixe the article title problem?
- Why can posts never have a number as the link?
- Modify Post URL Programmatically
- Custom permalink for ‘post’ not working
- Permalink issue with new blog posts > getting 301 redirect