I am trying to add facebook share functionality to my wordpress posts.
in my wp loop i have a share button

 <a class="action_button"  href="javascript:void(0)" id="share_button" target="_blank"> share this</a>

i am not getting post title ,post thumpnail etc. what is wrong with my code.

and before starting loop i have javascript code like

<script>
  window.fbAsyncInit = function() {
     FB.init({appId: 'myappid', status: false, cookie: false, xfbml: false});
  };
  (function() {
     var e = document.createElement('script'); e.async = true;
     e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
     document.getElementById('fb-root').appendChild(e);
  }());
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#share_button').click(function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: '  <?php echo get_the_title(); ?>',
link: ' <?php echo get_permalink(); ?>',
picture: '<?php echo get_the_post_thumbnail();?>',
caption: 'This is the content of the "caption" field.',
description: 'This is the content of the "description" field, below the caption.',
message: ''
});
});
});
</script>

Read more here: facebook share functionality in wordpress loop


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: