jessica mele
jessica mele

Reputation: 435

adding a share button for Facebook on a Wordpress site

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

Upvotes: 1

Views: 8000

Answers (2)

ceejayoz
ceejayoz

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

Elijah Cruz
Elijah Cruz

Reputation: 171

  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.

Upvotes: -3

Related Questions