Customize Jetpack Related Posts
Changes the heading, number of posts and thumbnail visibility of Jetpack's Related Posts, and limits suggestions to posts from the last two years.
Opens WPIDE on
Code
$wpide_headline = 'You might also enjoy'; // Heading text.
$wpide_count = 3; // Posts to show (max 6).
$wpide_years = 2; // Only suggest posts from the last N years; 0 = no limit.
add_filter( 'jetpack_relatedposts_filter_headline', function () use ( $wpide_headline ) {
return '<h3 class="jp-relatedposts-headline"><em>' . esc_html( $wpide_headline ) . '</em></h3>';
} );
add_filter( 'jetpack_relatedposts_filter_options', function ( $options ) use ( $wpide_count ) {
$options['size'] = max( 1, min( 6, (int) $wpide_count ) );
return $options;
} );
add_filter( 'jetpack_relatedposts_filter_date_range', function ( $range ) use ( $wpide_years ) {
if ( ! $wpide_years ) {
return $range;
}
return array(
'from' => strtotime( '-' . (int) $wpide_years . ' years' ),
'to' => time(),
);
} );
Notes
Edit the values at the top. Jetpack can show at most 6 related posts.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.