How to Add Google +1 To WordPress Blog

If you’re using the Genesis Framework its easy to add this to your theme’s function.php – other themes use similar functions and hooks.

First add google plus one to the right of your post title.

add_action('genesis_post_title', 'google_plus_one');
function google_plus_one()
{
    if ( is_page() )
        return; // don't show google plus 1 on pages

    ?> <div class="plus_one"><g:plusone href="<?php the_permalink() ?>"></g:plusone></div>
<?php }

The add some CSS to float it right

.plus_one {
float:right;
margin:-40px 0;
}

Now add the google +1 javascript to your header so google can track the clicks.

add_action('genesis_post_title', 'google_plus_one_script');
function google_plus_one_script()
{
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<?php }
  • Trackback are closed
  • Comments (0)
  1. No comments yet.