Advertisement
geminilabs

[site-reviews] [site_review_random] shortcode

Jan 11th, 2021
1,644
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Registers the [site_review_random] shortcode to display a single random review
  3.  * Paste this in your active theme's functions.php file
  4.  *
  5.  * Shortcode options can be any of the "glsr_get_reviews" function arguments
  6.  * outlined in the documentation (except for "orderby" and "per_page").
  7.  *
  8.  * Note: this will obviously not work if your page is cached.
  9.  *
  10.  * @param array $atts
  11.  * @return string
  12.  */
  13. add_shortcode('site_review_random', function ($atts) {
  14.     $atts['orderby'] = 'random';
  15.     $atts['per_page'] = 1;
  16.     if ($reviews = apply_filters('glsr_get_reviews', null, $atts)) {
  17.         $html = $reviews->build();
  18.         return sprintf('<div class="%s">%s</div>', $html->style, $html);
  19.     }
  20. });
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement