• Resolved Paxjah

    (@paxjah)


    A quick snippet for anyone else looking, here’s how (or my version) on how to use the FontAwesome star icons for star ratings:

    /*
    Change testimonial star rating to stars
    */
    function hms_rating_override( $text ) {
    
    	$matches = null;
    	$getMatches = preg_match( '/data-rating=\"(\d)\"/', $text, $matches );
    
    	if ( count( $matches ) == 2 ) {
    
    		$rating = $matches[1];
    
    		if ( $rating == '1' ) {
    
    			return '<i class="fa fa-star"></i>';
    
    		} elseif ( $rating == '2' ) {
    
    			return '<i class="fa fa-star"></i><i class="fa fa-star"></i>';
    
    		} elseif ( $rating == '3' ) {
    
    			return '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>';
    
    		} elseif ( $rating == '4' ) {
    
    			return '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>';
    
    		} elseif ( $rating == '5' ) {
    
    			return '<i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i>';
    
    		}
    	}
    
    	return $text;
    }
    add_filter( 'hms_testimonials_system_rating', 'hms_rating_override' );

    https://wordpress.org/plugins/hms-testimonials/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Paxjah

    (@paxjah)

    If anyone has a better way of achieving this please let me know!

    Thank you!

    where do I put this code though?

    Also do you happen to know how I would go about editing the css to effect the layout of the testimonials. I.e.: img name rating date; next to testimonial. Kinda like yelp or any forum.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Use Font Awesome Stars for Rating’ is closed to new replies.