0

I'm using this code to change the permalink of posts to /blog

/** Cambiar slug de posts a blog */
function create_new_url_querystring() {
    add_rewrite_rule(
        'blog/([^/]*)$',
        'index.php?name=$matches[1]',
        'top'
    );

    add_rewrite_tag('%blog%','([^/]*)');
}
add_action('init', 'create_new_url_querystring', 999 );

function append_query_string( $url, $post, $leavename ) {

    if ( $post->post_type != 'post' )
            return $url;
    
    if ( false !== strpos( $url, '%postname%' ) ) {
            $slug = '%postname%';
    }
    elseif ( $post->post_name ) {
            $slug = $post->post_name;
    }
    else {
        $slug = sanitize_title( $post->post_title );
    }
    
    $url = home_url( user_trailingslashit( 'blog/'. $slug ) );

    return $url;
}
add_filter( 'post_link', 'append_query_string', 10, 3 );

But this only adds website.com/blog/%postname%. How can I modify to be /blog/%year%/%month%/%postname%?

I tried changing the permalink settings and not working.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.