I want to change the structure of yearly archive URL of default post type post.

As we know that default URL structure is like:

Default: http://wwww.domain.com/2005

but want them rewritten, so end up like this:

New: http://wwww.domain.com/archive/2005

I tried following but do seem to work:

function wpa116030_init(){
    global $wp_rewrite;
    $wp_rewrite->date_structure = 'archive/%year%/';
add_action( 'init', 'wpa116030_init' );

But it does not work.

I'd like someone to point to the right direction, need more info do leave a comment.



It should work but note that the date structure contains the structure for year, month and day archives as well, so you'll need something like:

add_action( 'init', function() {
    global $wp_rewrite;
    $wp_rewrite->date_structure = 'archives/%year%/%monthnum%/%day%';

Don't forget to visit your permalinks settings page in wp-admin so that rewrite rules are flushed.

  • This didn't work for me in June 2021
    – AdamJones
    Jun 22 at 23:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.