Skip to content

Instantly share code, notes, and snippets.

@adriannees
Created May 9, 2018 15:40
Show Gist options
  • Select an option

  • Save adriannees/0556d59d12388e20c8a107ec671cf860 to your computer and use it in GitHub Desktop.

Select an option

Save adriannees/0556d59d12388e20c8a107ec671cf860 to your computer and use it in GitHub Desktop.
Customize the Jetpack Related Posts Widget
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below into functions.php of your child theme.
//* This code courtesy of Jetpack
function jetpackme_filter_exclude_category( $filters ) {
$filters[] = array( 'not' =>
array( 'term' => array( 'category.slug' => 'category' ) )
); // Replace 'category' with the slug of the category to exclude
return $filters;
}
add_filter( 'jetpack_relatedposts_filter_filters', 'jetpackme_filter_exclude_category' );
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below into functions.php of your child theme.
//* This code courtesy of Jetpack
function jetpackme_append_related_post( $hits, $post_id ) {
// $post_id is the post we are currently getting related posts for
if ( 2194 == $post_id ) {
// Add specific post (post_id) to the front of the hits array
array_unshift( $hits, array( 'id' => 1036 ) );
// Remove the last element of the array
array_pop( $hits );
}
return $hits;
}
add_filter( 'jetpack_relatedposts_filter_hits', 'jetpackme_append_related_post', 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment