.

Web consulting

Integrating Google Reviews API into WordPress

    Add a header to begin generating the table of contents

    Introduction

    In today’s digital age, online reviews play a crucial role in the decision-making process of consumers. For businesses, these reviews are valuable as they provide an authentic and transparent snapshot of their service quality.

    Why Integrate Google Reviews on Your Site?

    Positive reviews enhance credibility and authenticity of your business in the eyes of site visitors. Additionally, customer reviews can boost your search engine rankings.

    hostinger-wordpress banner
    Looking for a reliable hosting solution to implement the features discussed? Check out Hostinger’s WordPress hosting plans for optimized performance and support. (affiliate link)

    How to Integrate Google Reviews on Your WordPress Site

    Before you start, ensure you have billing enabled in your Google Cloud account as the Google Places API is a paid service beyond a certain quota. Enable billing here.

    Here’s how to proceed with integrating Google Reviews on your WordPress site:

    Step 1: Retrieve Your Google Places API Key

    • Go to your Google API Console and log in.
    • Select or create a project.
    • Click on “APIs & Services” then “ENABLE APIS AND SERVICES”.
    • Search for “Places API” and enable it.
    • Copy your newly created API key. Restrict it to your domain for security.

    Step 2: Find Your Google Place ID

    • Use Google’s Place ID search tool.
    • Search for your business and copy the “Place ID”.

    Step 3: Create a PHP Snippet

    function trz_fetch_google_reviews($atts) {
        $api_key = "YOUR_API_KEY_HERE";
        $place_id = "YOUR_PLACE_ID_HERE";
    
        $url = "https://maps.googleapis.com/maps/api/place/details/json?placeid=$place_id&key=$api_key&language=en";
        $response = wp_remote_get($url);
    
        if( is_wp_error( $response ) ) {
            return;
        }
    
        $body = wp_remote_retrieve_body($response);
        $data = json_decode($body, true);
    
        $reviews_html = '';
    
        if( isset($data['result']['reviews']) ) {
            foreach( $data['result']['reviews'] as $review ) {
                $reviews_html .= '<div class="google-review">';
                $reviews_html .= '<p><strong>' . $review['author_name'] . '</strong></p>';
                $reviews_html .= '<p>' . $review['text'] . '</p>';
                $reviews_html .= '<p><em>Rated: ' . $review['rating'] . ' stars</em></p>';
                $reviews_html .= '</div>';
            }
        }
    
        return $reviews_html;
    }
    add_shortcode('trz_google_reviews', 'trz_fetch_google_reviews');

    Step 4: Use the Shortcode on Your Site

    • You can now use the shortcode [trz_google_reviews] in your posts, pages, or widgets to display Google Reviews on your site.

    Conclusion

    Integrating Google Reviews on your WordPress site not only adds a layer of authenticity and trust but also engages potential customers by showcasing real, positive experiences from other clients. This creates a bridge of trust and credibility, promoting a solid reputation online.

    If you have any questions or need additional assistance integrating your Google reviews on your website, feel free to contact us.

    How useful was this post?

    Click on a star to rate it!

    Average rating 5 / 5. Vote count: 8

    No votes so far! Be the first to rate this post.

    Leave a Comment

    Your email address will not be published. Required fields are marked *


      Add a header to begin generating the table of contents
      Home > Insights > Tutorials > Integrating Google Reviews API into WordPress