For reference, here is the code from the pastebin link:
/**
* Prefix the page/post excerpt with the Site Reviews rating summary
* Paste this in your active theme's functions.php file.
* @param string $excerpt
* @param \WP_Post $post
* @return string
*/
add_filter('get_the_excerpt', function ($excerpt, $post) {
$postTypes = ['page','post']; // Replace the values in this array with the desired post_types
if (in_the_loop() && in_array($post->post_type, $postTypes)) {
$shortcode = '[site_reviews_summary assigned_to=post_id hide=bars,summary,if_empty]';
return do_shortcode($shortcode).$excerpt;
}
return $excerpt;
}, 10, 2);
Notice that the code uses the in_the_loop function to check that it is only run in The Loop.
Since you are using a widget to display your post excerpts, it will not be using “The Loop”.
You can either remove this check:
if (in_array($post->post_type, $postTypes)) {
Or you can change it to only work if it is not in The Loop:
if (!in_the_loop() && in_array($post->post_type, $postTypes)) {
Also, you will want to make sure that you have changed this line to only include the post types that you want:
$postTypes = ['page','post']; // Replace the values in this array with the desired post_types
-
This reply was modified 4 years, 7 months ago by Gemini Labs.