Is there a way to disable date archives in WordPress?

For example, I don't want to have date archives (example.com/2021/06/11, for example) available at all. Is there a way to turn these archives off?

I found the following code snippet on Google, but it doesn't appear to alter anything.

add_action( 'template_redirect', 'remove_date_archives' );

function remove_date_archives() {
    // Check if we are on date archive page and return 404
    if ( is_date() ) {
        global $wp_query;

Any tips or links are appreciated. Thanks in advance.

  • That snippet works for me. What theme are you using? There may be other code that overrides the snippet. Have you tried searching for other instances of 'template_redirect'? Commented Nov 9, 2021 at 18:11
  • 1
    Also, what is your permalink structure? Commented Nov 9, 2021 at 18:18
  • Thanks for confirming the snippet is ok - the site theme is Hello-Elementor so I'm now thinking it's related to Elementors templating system? The permalink structure is using /%postname% Commented Nov 11, 2021 at 9:39
  • I tested Hello-Elementor and the Elementor plugin with their default settings, and the snippet still works. Where are you saving the snippet? You can also try using the Query Monitor plugin to see if your custom function is being called by the template_redirect hook. Commented Nov 11, 2021 at 18:09

1 Answer 1


Do you happen to use the Yoast SEO plugin? There is an option in the plugin under Search > Archives where you can switch off the Date archives. (and also Author archives if you want to).

  • thanks for your reply - we don't use Yoast for this site, and I'd rather not install a plugin for something this trivial. Commented Nov 9, 2021 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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