Jetpack: Related Posts: Add filter for post excerpt

Created on 6 Jan 2016  路  15Comments  路  Source: Automattic/jetpack

Some themes add shortcodes that aren't registered in the proper way, and thus don't get stripped from the post excerpt in our usual way. We could add a filter here to help users avoid having tons of shortcode spit out.

Good For Community Hacktoberfest Related Posts [Type] Enhancement [Type] Good First Bug

All 15 comments

See #2884 for more information.

Related: #3278.

We should probably consider adding a jetpack_sharing_display_markup filter that would cover each and every parameter of the Related Posts output. That would solve this issue, as well as others (#2164 and #2220 for example).

Update to my original post - if we just want to add a filter for the excerpt content, that would be done here now.

reported here: https://wordpress.org/support/topic/remove-tooltip-on-related-posts-thumbs/

Looks like Visual Composer is adding some shortcode into the title attribute.

Also suggested here: #7718

I also had a problem with Google indexing post excerpts in the related posts and found a way to remove the excerpts completely, which is to use the filter jetpack_relatedposts_returned_results to remove them from the raw data before it is used to render the results on the page.

function wr_jetpack_relatedposts_returned_results($results, $post_id) {
foreach ($results as $key => $subArr) {
$subArr['excerpt'] = '';
$results[$key] = $subArr;
}
return $results;
}
add_filter('jetpack_relatedposts_returned_results', 'wr_jetpack_relatedposts_returned_results', 10, 2);

You could also use this to strip HTML from the excerpt.

Hope that helps someone.

Thanks for mentioning it here @jenhooks.

I do not know why Jetpack adds such a huge hidden excerpt on every single related post. I know that it might help some "Accessibility" features for screen readers and such. But the problem is that even though the search engines claim to be smart enough to recognize such things, I do not think they will just ignore around 300-500 words enclosed in <p> tags (if the user has 6 related posts displayed for example) that are the exact beginning sentences of other articles (most people will not put different excerpts for posts.)

For example, let's say someone publishes a news article with 300 words and this excerpt thing exists on that page. It can be a big trouble unless the search engines can determine the purpose of the duplicate content on that page which is even more than the actual content.

Apart from that, even from an Accessibility point of view, I do not think it is a "Must" to have a long description attached to every single related post. We already have titles for that. It doesn't worth risking the rankings of every website that even doesn't know this excerpt is being put on their articles.

Also, thanks to @Salubritas for the code. Will try it.

Was this page helpful?
0 / 5 - 0 ratings