Facebook share button for Drupal views

Updated: 12 July, 2016 seen 5,987

Some time ago, I created a tutorial showing how you can add a Facebook like button to your Drupal powered site. That tutorial was pretty easy because we used a module. Today I'm willing to show, how to add Facebook share button to Drupal views page.

Go to Facebook developer center - https://developers.facebook.com/docs/plugins/share-button/ 

Generate your share button:

We will use HTML5.

Now you must add JavaScript SDK to your theme, you can load JavaScript with theme .info file

Once JavaScript is added to your theme - go to your views, and add a new field  - path, exclude it from your display, and move it under custom text field (custom text I use for views overrides)

Now open your custom text field and add HTML5 code from Facebook page, change url to [path] field:

<div class="fb-share-button" data-href="[path]" data-type="button_count"></div>

And in final you should get your views containing Facebook share button, with linking to each node in views. Save this view and display it in Drupal site using blocks.