Skip to main content

WordPress /blog Path Only For Posts

PHP
function custom_post_permalink_base() {
    // Check if the current request is for a singular post
    if ( is_singular( 'post' ) ) {
        // Add a rewrite rule to handle /blog/ as the base
        add_rewrite_rule(
            '^blog/([^/]+)/?',
            'index.php?name=$matches[1]',
            'top'
        );
    }
}
add_action( 'init', 'custom_post_permalink_base' );