X

Automatically add the Google +1 button

Adding this snippet to the functions.php of your wordpress theme will automatically add the Google +1 button to your wordpress posts. This is a great little snippet from ottopress.com


add_filter('the_content', 'google_plusone');
function google_plusone($content) {
	$content = $content.'<div class="plusone"><g:plusone size="tall" href="'.get_permalink().'"></g:plusone></div>';
	return $content;
}
add_action ('wp_enqueue_scripts','google_plusone_script');
function google_plusone_script() {
	wp_enqueue_script('google-plusone', 'https://apis.google.com/js/plusone.js', array(), null);
}

Comments  Leave a Reply

  1. Gadgets NewsLine November 30, 2011 at 3:10 pm

    Thanks for the share, will make a try of it.

    1. Glad to hear it!

  2. Does it works with the new asynchronous code?

    1. Hi Ana,
      Ill post an updated version with the asynchronous code,

      1. Thanks Kevin. I will put in footer.php for now. I think that your option is great for wordpress, thumblr .. etc users. What do you think?

        1. Hi Ana,
          This code will only work for wordpress.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!