Created
May 9, 2018 15:40
-
-
Save adriannees/0556d59d12388e20c8a107ec671cf860 to your computer and use it in GitHub Desktop.
Customize the Jetpack Related Posts Widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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