Add the following code to your theme’s functions.php file:
/**
* Replaces the title of a review with the first few words of the review text
* @param object $review
* @return object
*/
add_filter( 'site-reviews/get/review', function( $review ) {
$limit = 7; // change this number to the desired number of words
$split = 0;
if( str_word_count( $review->content, 0 ) > $limit ) {
$words = array_keys( str_word_count( $review->content, 2 ));
$split = $words[$limit];
}
$review->title = substr( $review->content, 0, $split );
return $review;
});
-
This reply was modified 7 years, 9 months ago by
Gemini Labs.
-
This reply was modified 7 years, 9 months ago by
Gemini Labs.
Thread Starter
BB1975
(@bb1975)
Thanks, Paul! What’s the best place to insert that code in the functions.php file — does it matter?
Thread Starter
BB1975
(@bb1975)
Incredible support — thank you so much.
Thread Starter
BB1975
(@bb1975)
Hi Paul, one more quick question: How do I add “…” immediately following the title text?
$review->title = substr( $review->content, 0, $split ).'…';
Thread Starter
BB1975
(@bb1975)
Thanks, Paul! Is there a way to eliminate the blank space between the last word in the title and the “…”?
$review->title = trim(substr( $review->content, 0, $split )).'…';
Thread Starter
BB1975
(@bb1975)
Brilliant. Thank you, Paul!