geminilabs

[site-reviews] Add the rating to the page title

Feb 13th, 2020 (edited)
306
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Append the Site Reviews rating summary stars, if they exist, to the Page titles
  3.  * Paste this in your active theme's functions.php file.
  4.  * @param string $title
  5.  * @param int $postId
  6.  * @return string
  7.  */
  8. add_filter('the_title', function ($title, $postId) {
  9.     if (in_the_loop() && is_page()) { // only proceed for pages
  10.         $shortcode = '[site_reviews_summary assigned_to=post_id hide="if_empty,bars,rating,summary"]';
  11.         $shortcode = do_shortcode($shortcode);
  12.         $shortcode = str_replace(['<div', '/div>'], ['<span', '/span>'], $shortcode); // replace block-level elements
  13.         return sprintf('<span>%s</span>%s', $title, $shortcode);
  14.     }
  15.     return $title;
  16. }, 10, 2);
RAW Paste Data Copied