Replace the WordPress Daily Archive Link with the Monthly

Replace the WordPress Daily Archive Link with the Monthly

Share on facebook
Share on twitter
Share on pinterest

When setting up this site with Elementor, we’ve run into a small nuisance. The post date linked to the day archive. Since we don’t post daily, let alone more than once per day, this archive never showed more than one post. See it for yourself, the daily archive still exists, but our automatic links never point to it. And that single post was always the one that sent you to the archive. Bummer! Therefore we found that the daily archive is meaningless for us. We are not sure how often this issue comes up with premium themes, but it’s up to the developers to decide which link to use. We haven’t found any admin options to influence to which archive the link points.

The code that changes the daily archive link

function convert_day_link_to_month_link( $daylink, $year, $month ) {
    return get_month_link( $year, $month );
}
add_filter( 'day_link', 'convert_day_link_to_month_link', 10, 3 );

This tiny snippet, once added to your site will convert daily archive links to monthly archive links. It uses the day_link filter/hook. Furthermore, it changes the get_day_link() function with the output of the get_month_link() function. It’ll affect links anywhere

It’s not Elementor-only! One caveat is that this will make the standard WordPress Calendar widget even more useless. While it’ll still show and highlight the days with a post, but every day of a given month will link to the monthly archive. If you use the Calendar, you probably don’t want this. As you can see, we have a different use case, and for us, this snippet makes perfect sense.

Why do you have two different date displays?

You might have noticed that we use two different dates. On the front page and in archives, you see the original publication date. However, in our single post layout, we have the last updated date (and the original publish date in the tooltip). We often go back to older articles to correct typos, add polls, or update obsolete information. We don’t want these edits to bump them to the front page again, even though we feel it’s necessary to show how recent should you consider a post.

This site is powered by Elementor

  • This site is powered by Elementor

Related Posts

Comments are closed.

Check out Justified Image Grid, my top-selling WordPress gallery that shows photos without cropping!

Show your photos with Justified Image Grid!