Adding A Google +1 Button To Your WordPress Blog

Adding A Google +1 Button To Your WordPress Blog

Tutorial Details
  • Program: WordPress + Any Browser
  • Version (if applicable): N/A
  • Difficulty: Medium
  • Estimated Completion Time: Less than 30 Minutes

Hyped as the next big thing since the Facebook ‘Like’ button – this tutorial explains how to add the Google +1 button to your site and extend your social network. I found that a plugin wasn’t working for me with another third-party plugin and I needed a solution so here it is for you all to use! This tutorial will show you how to make some simple modifications to your WordPress blog to show the button – without using a plugin.

In Google’s own words: The +1 button is shorthand for "this is pretty cool" or "you should check this out."

Requirements: To +1 posts or look at your own +1 statistics, you will need a Google Profile. In my opinion, all webmasters should have one (to make use of the excellent Google Webmaster Tools) but if you don’t, please visit the following link: Google: New Account.


Introduction

The Google +1 button is seen by some as a move by Google to close the gap between them and Facebook. Whether or not this is the case, it’s likely that this will become very popular similar to the ‘like’ button and should not be ignored by webmasters.

This tutorial will show you how to make some simple modifications to your WordPress blog to show the button – without using a plugin. I found that a plugin wasn’t working for me with another third-party plugin and I needed a solution so here it is for you all to use!


Step 1 Call the JavaScript Code from your Theme’s Footer File

The first thing you need to do is to add a snippet of code just before the </body> tag in your theme’s footer template. To do this, simply login to your WordPress Dashboard and click on: Appearance > Editor.

On the right-hand menu you should see a list of files that can be edited. Select the Footer (footer.php) file from this list. We’re going to add a small piece of code here to call the JavaScript from Google’s server which will handle the function of the button.

In the editor, scroll down until you find the </body> tag and copy/paste the following code directly above it.

%MINIFYHTML014e4bd23cf221fbbef679f7f5fd3b199%

Then click on the Update File button underneath the code.

Note: In certain themes, you may not be able to access the footer.php file, or find the </body> tag in it. In that case, you need to enter the following code into your theme’s functions file (functions.php)

function show_google_plus_one()
{ echo '%MINIFYHTML014e4bd23cf221fbbef679f7f5fd3b1910%';
}
add_action('wp_footer', 'show_google_plus_one');

This hooks into WordPress and will run every time the template calls the <pre>wp_footer</pre> function.

That’s it! Now it’s time to add the button to your site.


Step 2 Choosing your Button

The button can be styled in several ways. The easiest way to choose, is to visit the Google +1 website and create a custom button: Google +1 Your Website

Once you’ve chosen your preference, you’re ready to insert the code onto your site!


Step 3 Adding the Button

Now it’s time to decide where you want the button to appear on your site. The typical place for using this is at the top of individual Posts. You may already have the Facebook ‘like’ button installed so next to that could be a good start. Once you’ve decided, go back to the Dashboard and in the same window (Appearance > Editor) select the Single Post (single.php) from the right-hand menu. Locate the area you want the button to appear and paste the code from the Google +1 Button website into your single.php template file, then hit the UpdateFile button and that’s it!

 


Wrapping Up

I’m sure there are a hundred other great ways of accomplishing this (and yes, there’s bound to be lots of great plugins that might work for you as well), but I hope this little tutorial will help anyone out there trying to do this on their own. If you have any ways to improve this (or you have any questions), give me a shout in the comments!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.realtimetricks.com Irfan

    I’m having the G+ button in my profile and i don’t find any serious impact from G+ button so i may not consider it so seriously. Anyways a cool tut. Recommended.

  • viraj

    Thanks for this great post. Does the Google plus button display on IE7 browsers?

    • Tom Chubb
      Author

      Don’t see any reason why it shouldn’t. Let me know if you’re having problems getting it to work

      • http://www.elaljanelasola.com/ Elal Jane Lasola

        I’ve tried to open your site to IE9 and the G+ button was not shown.

        I have applied another code for it to be shown in IE9 and IE8 but doesn’t seem to be working in IE7.

        Do you or does anybody here possibly have a work around on this issue?

        Thanks!

  • http://8gramgorilla.com 8 Gram Gorilla

    I had trouble getting the +1 button to line up properly and also display at the same size as the FB and Twitter buttons. Out of curiosity, what are you using on this site for the social media sharing buttons? Add This/Share This? Seems to render very nicely.

    • Tom Chubb
      Author

      I’m a contributor to this site so I don’t know how they’re doing it I’m afraid.

      You could always use firebug in firefox to look at the CSS styles used and use them on your site.

  • Pingback: [Autopost] Leitura recomendada para 29/08/2011 a 30/08/2011 | As elucubrações do Caio Cesar

  • http://www.trapartists.com Preston Cross

    Very cool. Its always best to do things on your own rather than plugins usually.

    • http://www.plainandsimple.tv Tom Chubb
      Author

      I agree as I find some plugins conflict with each other and this way you have exact control over the placement.

  • http://www.iteracion.cl teorico

    muchas gracias.

  • Pingback: Add a Google +1 to your WordPress blog | Littleknowhow.com

  • Pingback: Add a Google +1 Button to your WordPress blog | Littleknowhow.com

  • spinndiva

    I have a WordPress blog and am an admin to a second one. I can’t select the “menu” in Appearance. Could it be only paid accounts have it? That would suck SO BAD! :(

  • http://www.google.com dotnet

    could anyone please solve the mystery of google plus working in ie7!!! atleast can you confirm that it supports or not? if it is then can you give the steps.. i will be very thankful to you guys.

  • Pingback: 30 Usefull WordPress Theme Tutorial | WordpressRadar.com - The Best Collection of Wordpress Tutorials on the Web

  • http://microsoft.com tmp
  • Pingback: Adding A Google +1 Button to Wordpress » VC-TEL Team Blog

  • http://www.des4x.com amrabdelaziz

    great tut >
    keep it up >

  • Pingback: Plugin - plovoucí nabídka? « Fórum podpory WordPressu