0

Here's the Google Plus One script I've been using:

<g:plusone a href="<?php echo urlencode(get_permalink($post->ID)); ?>"></g:plusone>

Worked fine until it didn't. Now it's returning a red Plus One button with a bunch of suggestions to correct the error, none of which apply.

Tried out the Plus One plugin, which works on single posts and pages, but screws up on custom post type pages. I'd rather not use a plugin.

Does anyone have a Plus One script that will work consistently with WordPress?

Thanks.

  • try using the plusone button generator and add it manually google.com/webmasters/+1/button – Sean Lee Sep 3 '11 at 17:51
  • Thanks, Sean, but again, we're talking about a PlusOne script that picks up the permalink and functions correctly. The generator does not account for permalinks. – user5486 Sep 5 '11 at 0:49
  • actually you can tweak the div where it renders the plus+ button, to wrap the permalink within, and adjust it using css so you can click to get to it. – Sean Lee Sep 5 '11 at 1:57
  • Sean, if you'll look at the script I posted in my question, you'll see that's what I tried to do. If you can produce a permalink-enabled script through the generator, I'd love to see it. – user5486 Sep 5 '11 at 20:51
  • instead of <g:plusone a href, use <g:plusone data-href... – Sean Lee Sep 6 '11 at 3:51
0

Google +1 is very easy to add to your site, you only need 2 things for a basic button.

1. Google's JavaScript, make sure its is https not http!

`<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>`

To add this to your site in your functions.php you can write,

function google_plus_gp() {
        wp_register_script( 'google-plus', 'https://apis.google.com/js/plusone.js');
    wp_enqueue_script('google-plus')
}
add_action ('wp_enqueue_scripts','google_plus_gp');

2. The markdown where you want the button.

<g:plusone></g:plusone>

You can add something like a content filter for after your posts.

add_filter('the_content', 'google_plus_plus');
function google_plus_plus($content) {
    $content = $content.'<div class="plusone"><g:plusone href="'.get_permalink().'"></g:plusone></div>';
    return $content;
}
  • Thanks, Wyck, but I need the PlusOne button to appear (and function properly) where I physically paste the script, and there only. How would I do that? – user5486 Sep 3 '11 at 19:02
  • The button will appear anywhere you put <g:plusone></g:plusone> – Wyck Sep 4 '11 at 5:34
  • Wyck, with your script, the button appears at the end of each blog entry. Picks up the url, yes, but that's not where I want the button. Yes, I physically pasted the markdown -- and all I got was the button, without the url. Basically, you left me back where I started. Please re-read my original question. – user5486 Sep 4 '11 at 13:47
-1

Here's the answer, courtesy of a sympathetic Google employee:

<g:plusone a href="<?php echo get_permalink($post->ID); ?>"></g:plusone>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.