Share facebook button displaying wrong information in "box_count"

4

In a wordpress-based project I'm working on, I have a modal that dynamically receives various information coming from a post-loop.

This modal serves as a kind of "Preview" the complete post.

Within this modal there must be sharing options (Facebook, + g, twitter, etc.).

The URLs that will be used by the share buttons are the urls of the full post. To pass the values dynamically I use JavaScript.

So far, everything works fine. The problem is that when you share the post, the facebook button counter does not increase. To view the current share number, you need to close the modal and open it again.

I think it is necessary to reopen the modal due to the use of FB.XFBML.parse (); to update the url.

I wonder if there is a way to reload the button to display the correct information without closing the modal? As a callback function to reload the facebook button when the user shares the content?

Part of the html code of the modal:

    <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/all.js#xfbml=1&version=v2.0";
           fjs.parentNode.insertBefore(js, fjs);
      }(document, 'script', 'facebook-jssdk'));
     </script>
     <fb:share-button id="fb_share_quick" href="#" layout="box_count" width="58"></fb:share-button>

Part of the javascript code that changes the url:

jQuery('.showPreview').on('click', function() {
    jQuery('fb\:share-button').attr('href', 'http://google.com');
    FB.XFBML.parse();
});

Can anyone give me any tips on how I can solve this?

    
asked by anonymous 15.09.2014 / 21:03

1 answer

1

I do not know if I understood correctly but from what I realized you want to show sharing buttons on the frontpage for the proper publications / posts is this?!

use this instead of loading more JS into your wordpress site:

HTML

<a class="random-class-button" href="http://www.facebook.com/sharer/sharer.php?u=<?php the_permalink() ?>" target="_blank"><img title="Facebook" alt="Facebook" width="38" height="38" src="http://2.bp.blogspot.com/-Lqo1eJjzHyE/UypQ90roR-I/AAAAAAAACyI/EOQYZGrz1qI/s1600/facebook-logo.png"></a>

CSS

.random-class-button{
/* background:green; personaliza a class à tua maneira */
}
    
19.09.2014 / 07:38