How do I share posts from my website on facebook?

Asked

Viewed 1,170 times

0

So, guys, I know a lot of people have a hard time with this. I set pretty much the open Graph meta tags, but the problem is that I wanted the share button to share the specific url post.

How do I do that ?

3 answers

1

You need to use the API by pointing to the current page url:

<div class="fb-share-button" data-href="URL DA SUA PÁGIA ATUAL" data-layout="box_count" data-size="large" data-mobile-iframe="true">
<a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=URL DA SUA PAGINA ATUAL COM ENCODE URI%2F&amp;src=sdkpreparse">Compartilhar</a>
</div>

To get the URL of the current page with PHP:

<?php echo 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>

To get the url of the current page with JS:

<script>var urlAtual = window.location.href; </script>

0

The best alternative, and the most functional, is remove the data-href of the share button properties, HTML5 version, in div. Remembering that you should have the SDK implemented, and also recommend the full open Graph. But if you have META TITLE, already scrolls the share... But: Instead of the Share plugin, it is currently used to implement the Like (or Recommend) button along with the Share plugin, which offers more options for the user .

Removed the data-href. Ready, will share the post from the URL you are! Within this same page Voce can have plugin elements share, with the data-href pointing to other Urls, if you want to share third Urls, being inside a main URL, for example .

I’ve been using it for years, and it’s the best alternative to your case .

0


You can use the facebook SDK.

Just load the SDK:

<!-- Load Facebook SDK for JavaScript -->
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

And then add the share button with your URL.

<!-- Your share button code -->
<div class="fb-share-button" 
  data-href="http://seusite.com/sua-pagina.html" 
  data-layout="button_count">
</div>

Official documentation: https://developers.facebook.com/docs/plugins/share-button

Browser other questions tagged

You are not signed in. Login or sign up in order to post.