Content Marketing

Limit Jetpack’s Related Posts To A Specific Date

Today, I was double-checking an article that I had written and noticed that the related post that came up was from 9 years ago on a platform that no longer existed. So, I decided to take a deeper look at the Jetpack related posts options on my site and see if I could limit the date range.

Jetpack does a fantastic job of selecting the relevant posts that are similar, but unfortunately, it has no idea that many of the articles may be out of date. I often remove old posts that make no sense, but I don’t have time to review all 5,000 articles I’ve written for over a decade!

Unfortunately, there’s no setting on Jetpack to accomplish this, you can only set whether or not you wish to have a headline, what the headline is, and options for the layout, whether to show thumbnails, whether to show the date, or whether to show any content.

related posts plugin jetpack

As with virtually everything in WordPress, though, there’s a robust API where you can customize your child theme (or theme’s) functions.php file and modify how it works. In this case, I want to limit the scope of any related posts to 2 years… so here’s the code:

function dk_related_posts_limit( $date_range ) {
    $date_range = array(
        'from' => strtotime( '-2 years' ),
        'to' => time(),
    );
    return $date_range;
}
add_filter( 'jetpack_relatedposts_filter_date_range', 'dk_related_posts_limit' );

This adds a filter to the query that the related posts plugin uses. I uploaded the update to my site and now the related posts are limited to anything written in the last 2 years!

There are additional ways of customizing your related posts as well, check out the Jetpack support page on the topic.

Disclosure: I’m using my WordPress and Jetpack affiliate links in this post.

Douglas Karr

Douglas Karr is the founder of the Martech Zone and a recognized expert on digital transformation. Douglas has helped start several successful MarTech startups, has assisted in the due diligence of over $5 bil in Martech acquisitions and investments, and continues to launch his own platforms and services. He's a co-founder of Highbridge, a digital transformation consulting firm. Douglas is also a published author of a Dummie's guide and a business leadership book.

Related Articles

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close

Adblock Detected

Martech Zone is able to provide you this content at no cost because we monetize our site through ad revenue, affiliate links, and sponsorships. We would appreciate if you would remove your ad blocker as you view our site.