Advertisement
geminilabs

[site-reviews] [site_reviews_random] shortcode

Jan 11th, 2021 (edited)
2,497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. /**
  2.  * Registers the [site_reviews_random] shortcode to display a random review
  3.  *
  4.  * Shortcode options can be any of the "glsr_get_reviews" function arguments
  5.  * outlined in the documentation (except for "orderby" and "pagination").
  6.  *
  7.  * Note: this will obviously not work if you are caching your pages.
  8.  *
  9.  * @param array $atts
  10.  * @return string
  11.  */
  12. add_shortcode('site_reviews_random', function ($atts = []) {
  13.     $atts = wp_parse_args(['orderby' => 'random', 'pagination' => false], $atts);
  14.     if ($reviews = apply_filters('glsr_get_reviews', null, $atts)) {
  15.         $html = $reviews->build();
  16.         return sprintf('<div %s>%s</div>', $html->attributes, $html);
  17.     }
  18. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement