My Wordpress site goes looking for an archive page if I append a year after the URL.

For example: http:/mysiteurl.com/my-site/2018. If there are posts from this year, it ends up redirecting to index.php for some reason. If there are no posts from that year, it goes to 404 page which is what I want. For example: http:/mysiteurl.com/my-site/2014 goes to a 404 page because there are no posts from that year, which is what I want.

My permalink structure is set to Post name which is like this http:/mysiteurl.com/my-site/sample-post/. So typing a year after the URL should display a 404 page, not show me archives.

Why is this happening?


WordPress generates date archives automatically, it's just a thing it does. You see the index.php template probably because there isn't a more specific one for date archives in your current theme. There are plugins that disable these archives, Yoast SEO is one.

A quick fix is to empty the date archive rewrite rules:

add_filter( 'date_rewrite_rules', function( $rules ){
    return array();
} );

Visit the Settings > Permalinks page after adding this to flush rules.

| improve this answer | |
  • This works! I don't know why it does that when I set my permalink structure to "Post name". I thought if there's no page or post named "2018" then it should show the 404 page. Thanks for the help! (also I have registered some Custom Post Types if that makes a difference but they all have has_archive => false) – Justin Breen May 7 '18 at 4:52

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.