1

I have a Drupal 7 site. I'd like to add Social Media follow buttons (i.e. Follow us on Facebook, Twitter, Linkedin). I grabbed some Javascript code from http://www.addthis.com which generates these buttons and also links to some analytics services I will be using. Now I need to figure out how to place the AddThis Javascript code I generated, to a Drupal block. Once it's in a block, it will be easy for me to move around my Drupal site pages.

2 Answers 2

2

Why not just use the addthis module rather than adding a block. If you however want to add a block, just go to admin/structure/block click on add block. Paste your script in and select filter type of php code and click save

If you do not have PHP filter in the filter type, enable it under the core module

5
  • The other alternative is creating a custom block in a custom module, but the addthis module works fine for most cases.
    – rooby
    Commented Jul 16, 2013 at 23:00
  • Just to mention that save php into the DB is not a good choice. DB should store content and not the system logic.
    – revagomes
    Commented Jul 17, 2013 at 0:04
  • The addthis module is for sharing buttons, not for "Follow us" buttons. Perhaps I missed something when I installed and played with the module. Commented Jul 17, 2013 at 3:49
  • 4life, you're solution was simple and it worked perfectly. I just added a block, selected PHP and pasted in the javascript. Thanks! Commented Jul 17, 2013 at 5:12
  • Sorry, in order to add Social Media follow buttons you can use the Follow module.
    – revagomes
    Commented Jul 17, 2013 at 18:40
0

In order to add Social Media follow buttons you can use the Follow module. If you need to add Social Media share buttons you can use the AddThis module or the Easy Social module.

To attach CSS or JS files to a specific block you will need to build a custom module that implements the hook_block_view_alter to manipulate the block render array and then use Drupal 7 FAPI's #attached attribute to attach the file to the block.

3
  • The addthis module is for share buttons, not for follow us buttons. Perhaps I missed something. Commented Jul 17, 2013 at 3:50
  • Sorry, I've edited the answer to add the module for follow buttons.
    – revagomes
    Commented Jul 17, 2013 at 18:38
  • Also, I'm sticking with the Addthis code, I'm glad to know about the Follow module and I'm sure others reading this thread will want to know about. Commented Jul 17, 2013 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.