Like many other, I would like to have:
domain.com/post-title
changed into
domain.com/blog/post-title
but only for the post type ‘post’, not for ‘page’ and especially not for the custom post types (of which my theme seems to have many).
I have done my research on this forum and other sources and I know the general answer seems to be:
When you register your post type, the with_front argument of rewrite should be false.
$args = array(
'rewrite' => array( 'with_front' => false ),
);
register_post_type( 'your-post-type', $args );
Unfortunately, this does not help the beginners. We don’t know what is meant by the instructions above. Apparently we should somehow re-register the default post type “post” (although the post type “post” already exists and is in use), but we don’t know how and where to do that. If anyone can shed some light on the necessary procedure for changing the blog posts URLs, I would be most grateful.
I found the answer here. Remember to pop in there and give it a like.
I’ll post it here, for people in a rush.
Put this into the functions.php
-file:
function wp1482371_custom_post_type_args( $args, $post_type ) {
if ( $post_type == "post" ) {
$args['rewrite'] = array(
'slug' => 'blog'
);
}
return $args;
}
add_filter( 'register_post_type_args', 'wp1482371_custom_post_type_args', 20, 2 );
(Tested and works).
Remember!!
Remember A) Remember to update your permalinks afterwards (by going into Settings >> Permalinks >> Click ‘Save Changes’ ).
Remember B) If you get wierd results, then try opening an incognito-window and see if it words there. WordPress has a feature that redirects to ‘Nearest Matching URL’, that can seem confusing, when playing around with permalinks.
You could also try to find a Plugin that does it. I wouldn’t do that, since it’s quite extensive to add a plugin for that sole purpose. But hey, – sometimes it can be satisfying to shoot birds with canons (no bird was harmed making this joke).