Source file: modules/related-posts/jetpack-related-posts.php
View in GitHubParameters
- $this->to_utf8(
-
(string) $this->generate_related_post_context( $post->ID ) ) Context displayed below each related post.
- $post_id
-
(int) Post ID of the post for which we are retrieving Related Posts.
Changelog
Since: Jetpack 3.0.0
Notes
By default, Jetpack adds a category name, a tag name, or “Similar Post” under each one of the Related Posts on your site.
You can use the jetpack_relatedposts_filter_post_context
filter to remove, or edit this context.
To remove that context, you can just ask the filter to return an empty string, like so:
add_filter( 'jetpack_relatedposts_filter_post_context', '__return_empty_string' );
To add more information, you can follow the example below, where we add the author name to the Related Post context:
/** * Display the post author after the existing Related Posts context. * * @param string $context Context displayed below each related post. * @param string $post_id Post ID of the post for which we are retrieving Related Posts. * * @return string $context Context, including information about the post author. */ function jeherve_related_authors( $context, $post_id ) { // Get the author ID. $post_author = get_post_field( 'post_author', $post_id ); // Get the author's display name. $author_display_name = get_the_author_meta( 'display_name', $post_author ); // Add the author name after the existing context. if ( isset( $author_display_name ) && ! empty( $author_display_name ) ) { return sprintf( __( '%1$s<span class="jp-relatedposts-post-author">By %2$s</span>', 'my-plugin-slug' ), $context, esc_html( $author_display_name ) ); } // Final fallback. return $context; } add_filter( 'jetpack_relatedposts_filter_post_context', 'jeherve_related_authors', 10, 2 );