Monday, September 19, 2022
HomeWordPress DevelopmentPosts construction named to weblog, the best way to add month and...

Posts construction named to weblog, the best way to add month and yr


I am utilizing this code to vary the permalink of posts to /weblog

/** Cambiar slug de posts a weblog */
perform create_new_url_querystring() {
    add_rewrite_rule(
        'weblog/([^/]*)$',
        'index.php?identify=$matches[1]',
        'high'
    );

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

perform append_query_string( $url, $publish, $leavename ) {

    if ( $post->post_type != 'publish' )
            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( 'weblog/'. $slug ) );

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

However this solely provides web site.com/weblog/%postname%. How can I modify to be /weblog/%yr%/%month%/%postname%?

I attempted altering the permalink settings and never working.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments