How to Customize Archive Date Notation in WordPress

By default, dates displayed in WordPress archive links and widgets are denoted by “year” and “month”. However, if you wish to change this notation, you can customize it using specific filter hooks.

The following method shows how to change the date notation in archives to the “year / month” format.

// Replace the year notation in wp_get_archives 
function my_archives_link($html){ 
 $html = str_replace('year',' / ',$html); 
 $html = str_replace('month','',$html); 
 return $html; 
} 

add_filter('get_archives_link', 'my_archives_link'); 

// Replace year notation in archive widget 
function my_archives( $html ){ 
 $html = str_replace('year ',' / '',$html); 
 $html = str_replace('month',''',$html); 
 return $html; 
} 

add_filter( 'widget_archives_args','my_archives'); 

Adding the above code to your theme’s functions.php will change the date notation in archive links and archive widgets to “year / month”.

This method is useful for designs that call for a specific date format or for displays that are easy for readers to understand.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top