How to change the description of the Star Rating titles on hover

When hovering over a star to rate an entry, the titles are by default:

  1. 1 star
  2. 2 stars
  3. 3 stars
  4. 4 stars
  5. 5 stars

But what if you have a custom rating scale that you want to display when users hover over the star? For example, if you wanted to use Netflix's rating scale: Hated it, Didn't like it, It was okay, Liked it, Loved it, you can use the code below.

/**
 * Change the titles displayed when hovering over a star to use the Netflix scale
 * @param  array $stars Star titles
 * @return array        Modified titles
 */
function gv_ratings_reviews_use_netflix_scale( $stars ) {
	
	// Make sure to keep the array key numbers intact; they map with the star rating.
	// You can also set an empty string to disable the title attribute from appearing.
	$stars = array(
		1 => 'Hated it',
		2 => 'Didn\'t like it',
		3 => 'It was okay',
		4 => 'Liked it',
		5 => 'Loved it',
	);

	return $stars;
}

add_filter('gv_ratings_reviews_star_rating_titles', 'gv_ratings_reviews_use_netflix_scale');

Read here how to add these code samples to your website: Where to put code samples.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us