Title: Render reviews from PHP without shortcode
Last modified: September 23, 2020

---

# Render reviews from PHP without shortcode

 *  Resolved [Devomo](https://wordpress.org/support/users/devfirst/)
 * (@devfirst)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/render-reviews-from-php-without-shortcode/)
 * Hi there,
 * First of all, I must say I really like this plugin. It has saved me a ton of 
   time.
 * I only was wondering: if I want to customize a lot of things, the shortcode is
   not exactly short any more. So for a recent project, I solved that like this:
 *     ```
       $reviews_args = [
           'summary="no"',
           'review_item_order="author switch text first"',
           'date="off"',
           'excerpt=""',
           'reviews_link="reviews via Google"'
       ];
       $reviews = do_shortcode('[reviews_rating ' . implode(' ', $reviews_args) . ']');
       ```
   
 * Not the most elegant solution, but it gets the job done.
 * What I was looking for, is a function/action I can just pass my `$reviews_args`
   to, without needing to render the shortcode. I searched the plugin code, but 
   I could not find any other way to render the reviews than through `do_shortcode()`.
   Or am I missing something?
 * If such a function/action does not exist: it could be as simple as adding an 
   action (as well as a shortcode). One line of code in the plugin would do:
 *     ```
       add_action('reviews_rating', array($this, 'wp_display'));
       ```
   
 * in the plugin’s `google_business_reviews_rating` class.
 * That would enable me to do:
 *     ```
       $reviews_args = [
           'summary' => 'no',
           'review_item_order' => 'author switch text first',
           'date' => 'off',
           'excerpt' => '',
           'reviews_link' => 'reviews via Google'
       ];
       do_action('reviews_rating', $reviews_args);
       ```
   
 * instead of using `do_shortcode()`.
 * Just meant as a suggestion, curious what you think 🙂
    -  This topic was modified 5 years, 8 months ago by [Devomo](https://wordpress.org/support/users/devfirst/).

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Noah Hearle](https://wordpress.org/support/users/designextreme/)
 * (@designextreme)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/render-reviews-from-php-without-shortcode/#post-13445719)
 * [@devfirst](https://wordpress.org/support/users/devfirst/) Thanks for getting
   in touch about this. I’m really glad that you’ve found the plugin useful – I’ve
   aimed this plugin at moderate to expert WordPress users because there are so 
   many design/tweaks/customizations etc. that are possible with a base level of
   knowledge.
 * I will have a look at the `do_shortcode()` function and perhaps adding a new 
   action in the next day or so…
 * Are you able to achieve the same outcome using `do_shortcode()` to a variable?
 * What you’ve said here all adds up, but I’m away from my computer for a bit. I’ll
   reply again when I have more to say after a few tests on my side.
 *  Thread Starter [Devomo](https://wordpress.org/support/users/devfirst/)
 * (@devfirst)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/render-reviews-from-php-without-shortcode/#post-13447076)
 * [@designextreme](https://wordpress.org/support/users/designextreme/) thanks for
   the quick response.
 * > Are you able to achieve the same outcome using do_shortcode() to a variable?
 * I’m not entirely sure what you mean by this, but at least it made me realize 
   that it is not as simple as I thought. After all, a shortcode _returns_ content,
   and I now assume the `do_action()` call will _echo_ it. So maybe you will need
   a function after all, or create a dedicated method which echoes the shortcode
   content and add that as an action.
 * The reason I suggested an action instead of a function is the fact that as a 
   theme developer, I will always have to check whether a plugin-provided function
   exists. If I use an action, I will not have to do that, it will simply do nothing
   if no listeners are attached.
 *  Plugin Author [Noah Hearle](https://wordpress.org/support/users/designextreme/)
 * (@designextreme)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/render-reviews-from-php-without-shortcode/#post-13449102)
 * [@devfirst](https://wordpress.org/support/users/devfirst/) I am back on my laptop
   and re-reading the messages…
 * I don’t quite understand why using `do_shortcode()` is such a bad thing. You 
   can add something like this to your [custom] theme:
 *     ```
       $reviews = '';
   
       if (is_plugin_active('g-business-reviews-rating/g-business-reviews-rating.php'))
       {
       	$reviews = do_shortcode('[reviews_rating summary=false review_item_order=\'author switch text first\' date=false excerpt=null reviews_link=\'Reviews via Google\'']);
       }
   
       // Later:
   
       echo $reviews;
       ```
   
 * Having a long list of arguments isn’t a bad thing, you can make it very long 
   with no issues at all.
 * Please contact me directly as it may be easier to discuss in a different format
   such as WhatsApp or Skype. Details on [my website](https://designextreme.com/wordpress),
   under Contact Us.
 *  Thread Starter [Devomo](https://wordpress.org/support/users/devfirst/)
 * (@devfirst)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/render-reviews-from-php-without-shortcode/#post-13452347)
 * [@designextreme](https://wordpress.org/support/users/designextreme/) It’s not
   _bad_, it does the job. But in my opinion, such a long shortcode is not very 
   elegant, nor is it very readable. It’s not about the functionality, just about
   the developer experience.
 * I’d rather have the arguments as an array, one per line, and pass them to a function
   or action. I think that would be less error-prone, too.
 * If it’s not clear to you, I’d be happy to get in touch.
    -  This reply was modified 5 years, 8 months ago by [Devomo](https://wordpress.org/support/users/devfirst/).
 *  Plugin Author [Noah Hearle](https://wordpress.org/support/users/designextreme/)
 * (@designextreme)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/render-reviews-from-php-without-shortcode/#post-13453393)
 * [@devfirst](https://wordpress.org/support/users/devfirst/) The reason for the
   continuation off the forums is to understand why you are looking for a different
   method. If I can understand it and see the benefits, I’ll introduce this new 
   functionality into a future release of the plugin.
 * If the answer is just to get away from the ugly string argument needed to run`
   do_shortcode()`, then it isn’t going to be a major priority.
 * You can introduce your own shortcode handler function where you can pass an array
   of the parameter keys and values (or have it live in the function) and this will
   return the HTML of the shortcode to use wherever you wish. However, this is still
   going to use the `do_shortcode()` function somewhere but it will assist in moving
   the code excerpt out of the theme’s template files.
 *  Thread Starter [Devomo](https://wordpress.org/support/users/devfirst/)
 * (@devfirst)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/render-reviews-from-php-without-shortcode/#post-13461695)
 * [@designextreme](https://wordpress.org/support/users/designextreme/) The only
   real benefit here is a better developer experience, I think that’s clear, so 
   I do not feel the need to continue the discussion off the forums.
 * I understand that this is just a small improvement, which does not have your 
   top priority. I came up with the suggestion because I felt it could be accomplished
   with minor effort on your part.
 * But it was just a suggestion after all 🙂
 *  Plugin Author [Noah Hearle](https://wordpress.org/support/users/designextreme/)
 * (@designextreme)
 * [5 years, 8 months ago](https://wordpress.org/support/topic/render-reviews-from-php-without-shortcode/#post-13462551)
 * [@devfirst](https://wordpress.org/support/users/devfirst/) I understand what 
   you’re looking for here.
 * I can write a function, external to the plugin, that can be added to your theme’s
   development or **functions.php**. It will basically parse an array, run a check
   on the plugin’s status and off it goes…

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Render reviews from PHP without shortcode’ is closed to new replies.

 * ![](https://ps.w.org/g-business-reviews-rating/assets/icon.svg?rev=2722684)
 * [Reviews and Rating – Google Reviews](https://wordpress.org/plugins/g-business-reviews-rating/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/g-business-reviews-rating/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/g-business-reviews-rating/)
 * [Active Topics](https://wordpress.org/support/plugin/g-business-reviews-rating/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/g-business-reviews-rating/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/g-business-reviews-rating/reviews/)

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)
 * [rendering](https://wordpress.org/support/topic-tag/rendering/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 7 replies
 * 2 participants
 * Last reply from: [Noah Hearle](https://wordpress.org/support/users/designextreme/)
 * Last activity: [5 years, 8 months ago](https://wordpress.org/support/topic/render-reviews-from-php-without-shortcode/#post-13462551)
 * Status: resolved