Home / functions.php / Automatically add the Google +1 button
  • Automatically add the Google +1 button

    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

    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,
  • http://wellbeing-support.com Ana Peterson

    Does it works with the new asynchronous code?

    • http://wpsnipp.com Kevin Chard

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

      • http://wellbeing-support.com Ana Peterson

        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?

        • http://wpsnipp.com Kevin Chard

          Hi Ana,
          This code will only work for wordpress.

  • http://gadgetsnewsline.com/ Gadgets NewsLine

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

    • http://wpsnipp.com Kevin Chard

      Glad to hear it!

Build a better with wpsnipp.com

Weekly snippets, themes, deals coupons roundup.

x No Thanks