1
votes

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: enter image description here

2
Give us the actual URL you're passing it.ceejayoz
(Also, chances are you need to run the_permalink() through urlencode() to escape special characters.)ceejayoz
@ceejayoz I'm working locally, the url is: localhost:8080/videos/test-2-testingjessica mele

2 Answers

5
votes

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()) ?>" ...>
-3
votes
  1. In Your WordPress Admin Area, select Plugins > Add New from the menu.
  2. Search for “ShareThis”
  3. Install the “ShareThis: Share Buttons and Sharing Analytics” plugin.
  4. Activate the Plugin.

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.