Adding Google +1 Button to WordPress

The Google +1 button was released not too long ago, and it seems that everyone has already added it to their website or WordPress blog. WPExplorer.com was one of the first to test it out, and they have created a short function that will automatically add the button to all of your posts. If you want to show other social buttons along with the plus 1 button, you can easily do so by adding them inside the same function.

Here are three easy steps showing you how to create a Google Plus One button function in your theme so it automatically adds the button to all your posts.

Step 1: Include the Javascript

The Google Plus 1 button requires that you call the Google +1 API in your HEAD section. To do so, simply paste the following code into your functions.php file:

function google_plus_one_script() {

?>

}

add_action(‘wp_head’, ‘google_plus_one_script’);

Step 2: Add a Function for Your Button

Next, you’ll want to create the function that adds the actual button to your posts. This function will run only on your single posts, and it will add the button right before the main loop:

function google_plus_one_button() {

if (is_single()) {

?>

}}

add_action(‘loop_start’, ‘google_plus_one_button’);

Step 3: Hook Your Function to the Top or Bottom of Your Post Loop

Finally, you need to hook your function to the top or bottom of your post loop. Below is what your full code should look like that you will be inserting into your functions.php file or custom_functions.php file if you are using a child theme like Thesis.

// add google +1 script to WordPress HEAD

function google_plus_one_script() {

?>

}

add_action(‘wp_head’, ‘google_plus_one_script’);

// add button function

function google_plus_one_button() {

if (is_single()) {

?>

}}

// attach function to hook

add_action(‘loop_start’, ‘google_plus_one_button’);

By following these three easy steps, you can easily add the Google +1 button to your WordPress website or blog. This will help increase your website’s visibility and improve your search engine rankings.

Stay in Touch

spot_img

Related Articles