I did little tweak for date archive permalink.

function my_rewrite_rules($wp_rewrite){
    $rules = array();
    $rules['news/([0-9]{4})/?$'] = 'index.php?year=$matches[1]';
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;
}

add_action('generate_rewrite_rules', 'my_rewrite_rules');

Then hit the url below.

http://blahblah.blahblah/wp/news/2017/

This successfully shows posts belong to 2017.

Now I want to generate the links for date archive, but this doesn’t generate the code I want.

get_year_link($year);

Still generate the default permalink like this:

http://blahblah.blahblah/wp/date/2017/

So how do I tell wordpress what permastructure to use?
Otherwise I may have to hard code…

2 Answers
2

You can change the date links by directly modifying the date_structure:

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

Don’t forget to flush rewrite rules after the change.

WordPress will use this to generate the rewrite rules for incoming requests as well as URL output when using API functions like get_year_link, so there’s no need for a filter.

Leave a Reply

Your email address will not be published. Required fields are marked *