Site icon Hip-Hop Website Design and Development

How to disable date archives?

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;
        $wp_query->set_404();
    }
}
?>

Any tips or links are appreciated. Thanks in advance.