Table of Contents

Google Plus One Button WordPress

I received a ton of emails recently asking how to use the Google Plus One Button on a WordPress site.

This is extremely easy to do. You can set up everything from inside of WordPress with a few simple copies and pastes.

So, open up your WordPress dashboard on your favorite browser and we’ll be done in a few minutes.

Paste Google Plus One Code in Header.php

First click on Appearance in your WordPress left sidebar and click Editor.

Under Templates in your right sidebar click on the file named header.php. Copy and paste the following line between the <head> tags that you find here:

<script type=”text/javascript” src=”https://apis.google.com/js/plusone.js”></script>

Note: Make sure you don’t paste this between opening and closing php tags.

After you copied and pasted the code click on the update button.
Create a WordPress Shortcode for Google Plus One Button
Now we’ll create a shortcode that will allow you to easily place a Google Like Button where ever you’d like.
Click on the file named functions.php in the WordPress Appearance editor. At the end of that file paste in the following code:

<?php

// This code places a Google +1 Button in a post
function showgoogleplusone() {
return ‘<g:plusone></g:plusone>’;
}

add_shortcode(‘googleplusone’, ‘showgoogleplusone’);

Again, watch out for the opening and closing php tags. Don’t paste this between them! Click the update button and now when you type [ googleplusone ]  in your WordPress posts a Google Plus One button will show up instead like this

[googleplusone]

Note: make sure you don’t have spaces before and after the words googleplusone in the shortcode above.

Want to Learn More about WordPress

If you want to learn more about WordPress I have the only WordPress Theme and Plugin video Tutorials on the internet here WordPress Theme Development.

Leave any questions or comments below. If you like my site please click that Google +1 Button 🙂 I appreciate it

hi i would like to implement this too but when i update the functions.php as you said i have a blank website.

i think because there is a bug in functions.php

Make sure you don’t have any spaces after the php tags < ?php or ?>

This causes WordPress to go nuts 🙂

Hi there,
thanks a lot for this helpful site. Finally I got it working!
But what almost drove me crazy are the typographic quotes you are using in the code. Copy & paste doesn’t work and it’s hard to find out why …

Plus you’ll need a rel=”canonical” for the button to work properly.

Cheers,
Christoph

Definitely! The easiest way to do that is with JQuery and AJAX techniques. Here is a video AJAX Video Tutorial.

I’d probably just store the number of clicks in a text file. Pretty simple to set up. Kind of like a hit counter that is tied to clicks on your button

Your email address will not be published.

This content was originally published here.