Advertisement
geminilabs

[site-reviews] Use an excerpt of the review for the title

Aug 29th, 2018
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  1. /**
  2.  * Replaces the title of a review with the first few words of the review text
  3.  * @param object $review
  4.  * @return object
  5.  */
  6. add_filter( 'site-reviews/get/review', function( $review ) {
  7.     $limit = 6; // change this number to the desired number of words
  8.     $split = 0;
  9.     if( str_word_count( $review->content, 0 ) > $limit ) {
  10.         $words = array_keys( str_word_count( $review->content, 2 ));
  11.         $split = $words[$limit];
  12.     }
  13.     $review->title = substr( $review->content, 0, $split );
  14.     return $review;
  15. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement