How to Remove the Archives Directory from WordPress URLs

wordpress archivesremove archives urlwordpress permalink structureclean date linkswordpress functions.php
Published·Modified·

By default, WordPress category directories include the word "archives," which increases link length and looks less appealing. It is also not very friendly for search engines. However, removing this prefix is very simple.

Add the following code to the functions.php file in your theme directory:

// Remove archives
add_filter('date_rewrite_rules', 'remove_date_permalink_prefix'); 
function remove_date_permalink_prefix($rules) { 
return array_combine( array_map('_rdpp_replace', array_keys($rules)) , array_values($rules) ); 
} 

foreach ( array( 'year_link', 'month_link', 'day_link') as $filter ) 
add_filter( $filter, '_rdpp_replace' ); 

function _rdpp_replace($s) { 
return str_replace('archives/date/', 'date/', $s); 
}
// End of removing archives

Some users might ask, "If you say 'archives' is not friendly, why hasn't your blog removed it?" The truth is, I also wanted to remove it. However, my blog has been running for several months, and I dare not change the link structure arbitrarily, so I had to make do with the current setup. For new WordPress sites, I have already adopted this method, and I hope it helps everyone.