Facebook share functionality in wordpress loop

The Javascript is outside the loop, so php can never access get_the_title(), get_permalink() and get_the_post_thumbnail() from there.

What I’d do is include those somewhere in the loop, for instance:

<div class="entry-content">
    <h2 class="post-title"><?php the_title(); ?></h2>
    <a class="share-button" data-title="<?php the_title(); ?>"></a>
</div>

Then with jQuery, you can grab them from the HTML generated by the loop. For instance the following (and do the same for link and picture):

<script type="text/javascript">
$(document).ready(function(){
    $('#share_button').click(function(e){
        e.preventDefault();
        var postTitle = $(this).data( "title" ); // Here's where you grab the title
        FB.ui({
            method: 'feed',
            name: postTitle,
            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>