geminilabs

[site-reviews] Prefix the excerpt with the rating summary

May 3rd, 2018 (edited)
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. /**
  2.  * Prefix the page/post excerpt with the Site Reviews rating summary
  3.  * Paste this in your active theme's functions.php file.
  4.  * @param string $excerpt
  5.  * @param \WP_Post $post
  6.  * @return string
  7.  */
  8. add_filter('get_the_excerpt', function ($excerpt, $post) {
  9.     $postTypes = ['page','post']; // Replace the values in this array with the desired post_types
  10.     if (in_the_loop() && in_array($post->post_type, $postTypes)) {
  11.         $shortcode = '[site_reviews_summary assigned_posts=post_id hide=bars,summary,if_empty]';
  12.         $shortcode = do_shortcode($shortcode);
  13.         return $shortcode.$excerpt;
  14.     }
  15.     return $excerpt;
  16. }, 10, 2);
Add Comment
Please, Sign In to add comment