Open your functions.php file and paste the following code in it:
add_filter('the_content', 'wpr_google_plusone');
function wpr_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','wpr_google_plusone_script');
function wpr_google_plusone_script() {
wp_enqueue_script('google-plusone', 'https://apis.google.com/js/plusone.js', array(), null);
}
Once saved, a Google+ button will be automatically added to all your posts.
Thanks to Spyre Studios for the great piece of code!
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
WordPress hook: Automatically add a Google+ button to your posts