How to Remove WordPress Archives Directory

Publish: 2014-09-01 | Modify: 2018-08-03

WordPress default category directory comes with "archives", which increases the length of the links and doesn't look very pleasant. It is also not very search engine friendly. However, removing it is quite simple. Add the following code to the "functions.php" file in your theme directory.

// Remove "archives" from permalinks
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 of you may ask, if "archives" is not friendly, why haven't you removed it from your blog? Well, I did want to remove it, but my blog has been up for several months and I didn't want to change the structure of the links. So I had to compromise. However, for new WordPress sites, I have used this method and I hope it will be helpful to all of you.


Comments