Home / functions.php / Automatically add the Google +1 button
  • How to 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

    ( click code to copy )

    wordpress snippet : PHP

    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);

    ( WordPress codex functions, hooks, in this snippet. )

    the_content, get_permalink, add_filter, add_action, _e, wp_enqueue_script, wp,
  • Does it works with the new asynchronous code?

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

      • 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?

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

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