Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Append the Site Reviews rating summary stars to the page title of Posts on single and archive pages
- * 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 this a single page?
- || is_home() // is this the blog page?
- || is_archive() // is this a post archive page?
- || is_category() // is this a category page?
- )) {
- $shortcode = '[site_reviews_summary assigned_posts="post_id" hide="bars,rating,summary"]';
- $shortcode = do_shortcode($shortcode);
- $shortcode = str_replace(['<div', '/div>'], ['<span', '/span>'], $shortcode); // replace block-level elements
- return sprintf('<span>%s</span>%s', $title, $shortcode);
- }
- return $title;
- }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement