Add ShareThis buttons to Drupal 7 without module

Marko RosicWeb DevelopmentLeave a Comment

If you’ve been building your site using Drupal 7 and wanted to add ShareThis buttons via module, you’ve probably seen that only version 6 is supported at the moment.

Fortunately this is not a big problem as you can add simple code to your template and have ShareThis in no time.

1 Get the code

Go to and choose Any Website under section 1, choose button type and style (Horizontal Counters in my case), and get the code.

2 Add code to template

ShareThis provides two &quote;sets&quote; of code. Buttons that go onto the page, and serve as placeholders for buttons, and scripts that go into the head of the page.

First one is added to node.php or wherever you want the buttons to be shown as such:

<div class="share-buttons">
    <span class="st_twitter_hcount" displayText="Tweet"></span>
    <span class="st_facebook_hcount" displayText="Share"></span>
    <span class="st_email_hcount" displayText="Email"></span>
    <span class="st_sharethis_hcount" displayText="Share"></span>

The second one can’t be added in form of script, but Drupal 7 provides excellent ways of inserting JS onto pages described here .

In this case you should copy parts of provided code as such in template.php:

drupal_add_js('<a href=""></a>', 'external');
drupal_add_js('stLight.options({publisher:\'PUBLISHER-ID\'});', 'inline');

This is all there is to it. Few lines of code and no modules are needed.


Previous Article
Next Article