Reputation: 435
I am trying to add a few social media share buttons to a Wordpress site I am working on and am using this for Facebook:
<a href="http://www.facebook.com/sharer/sharer.php?u=<?php the_permalink();?>" title="Share on Facebook." target="_blank"><img src="/img/facebook-blue.png" alt="Share this on facebook!" /></a>
but it is not seeming to work, it produces the correct link when I inspect the code "http://www.facebook.com/sharer/sharer.php?u=http://myurl/post-name" but when I click it I get this error on Facebook:
Upvotes: 1
Views: 8000
Reputation: 180014
I'm working locally, the url is: localhost:8080/videos/test-2-testing
You'll find Facebook's sharer.php won't work with any localhost URLs.
The sharer scrapes an image, title, and description from the URL it's passed. As it can't access localhost (and allowing it to try actually would create potential security holes for Facebook), you get this error.
It'll likely work just fine in production, although you'll want to urlencode the URL, like this:
<a href="http://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode(get_permalink()) ?>" ...>
Upvotes: 5
Reputation: 171
This plugin can give you a facebook share button at the bottom and other buttons as well. This is what I use without having to write the code myself.
Upvotes: -3