The day_link WordPress PHP filter allows you to modify the permalink for the day archive.
Usage
add_filter('day_link', 'your_custom_function', 10, 4); function your_custom_function($daylink, $year, $month, $day) { // your custom code here return $daylink; }
Parameters
- $daylink (string) – Permalink for the day archive.
- $year (int) – Year for the archive.
- $month (int) – Month for the archive.
- $day (int) – The day for the archive.
More information
See WordPress Developer Resources: day_link
Examples
Add a custom prefix to day archive permalinks
This example adds a custom prefix daily/
to the day archive permalinks.
add_filter('day_link', 'add_custom_prefix_to_day_link', 10, 4); function add_custom_prefix_to_day_link($daylink, $year, $month, $day) { $daylink = str_replace(get_site_url(), get_site_url() . '/daily', $daylink); return $daylink; }
Change the date format for day archive permalinks
This example changes the date format in the day archive permalinks to YYYY/MM/DD
.
add_filter('day_link', 'change_date_format_in_day_link', 10, 4); function change_date_format_in_day_link($daylink, $year, $month, $day) { $daylink = get_site_url() . '/' . $year . '/' . $month . '/' . $day; return $daylink; }
Remove year from day archive permalinks
This example removes the year from the day archive permalinks.
add_filter('day_link', 'remove_year_from_day_link', 10, 4); function remove_year_from_day_link($daylink, $year, $month, $day) { $daylink = get_site_url() . '/' . $month . '/' . $day; return $daylink; }
Change the day archive permalink structure to a custom string
This example changes the day archive permalink structure to a custom string format archives/YYYY/MM/DD
.
add_filter('day_link', 'change_day_link_structure', 10, 4); function change_day_link_structure($daylink, $year, $month, $day) { $daylink = get_site_url() . '/archives/' . $year . '/' . $month . '/' . $day; return $daylink; }
Add a custom query parameter to day archive permalinks
This example adds a custom query parameter source=archive
to the day archive permalinks.
add_filter('day_link', 'add_custom_query_parameter_to_day_link', 10, 4); function add_custom_query_parameter_to_day_link($daylink, $year, $month, $day) { $daylink = add_query_arg('source', 'archive', $daylink); return $daylink; }