So, guys, I know a lot of people have a hard time. I configured the meta tags of open graph, but the problem is that I wanted the share button to share the specific post in the url.
How do I do this?
So, guys, I know a lot of people have a hard time. I configured the meta tags of open graph, but the problem is that I wanted the share button to share the specific post in the url.
How do I do this?
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: link
You need to use the API 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&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>
The best and most functional alternative is remove the date-href of the share button properties, HTML5 version, in div. Remember that you must have the SDK implemented, and the complete open graph is also recommended. But if you have META TITLE, the share ... However: Instead of the Share plugin, you are currently implementing the Like button (or Recomendar) along with the Share plugin, which offers more options for the user.
Removed the date-href .. Ready, will share the post of the URL you are! Within this same page you can have share plugin elements, with data-href pointing to other URLs, if you want to share third URLs, being within a main URL, for example.
I've been using it for years, and it's the best alternative for this case.