Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Append the Site Reviews rating summary stars, if they exist, to the page title
- * Paste this in your active theme's functions.php file.
- * @param string $title
- * @param int $postId
- * @return string
- */
- add_filter('the_title', function ($title, $postId) {
- $postTypes = ['post']; // change this as needed
- if (in_the_loop()
- && in_array(get_post_type($postId), $postTypes)
- && (is_single() || is_home() || is_category() || is_post_type_archive($postTypes))) {
- $shortcode = do_shortcode('[site_reviews_summary assigned_to="post_id" hide="bars,rating" text="<span class=\'num-stars\'>{rating} stars from</span> {num} reviews!"]');
- $shortcode = str_replace(['<div', '/div>'], ['<span', '/span>'], $shortcode); // replace block-level elements
- return sprintf('<span>%s</span>%s', $title, $shortcode);
- }
- return $title;
- }, 10, 2);
Add Comment
Please, Sign In to add comment