Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers

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

share|improve this answer
 
The other alternative is creating a custom block in a custom module, but the addthis module works fine for most cases. –  rooby Jul 16 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 Jul 17 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. –  user2398188 Jul 17 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! –  user2398188 Jul 17 at 5:12
 
Sorry, in order to add Social Media follow buttons you can use the Follow module. –  revagomes Jul 17 at 18:40

I don't have an answer, because I have exactly the same question for HTML, but I can't find another way to react. @4life: unfortunately, the addthis module doesn't exist for Drupal 7 in 'recommanded release' yet. I tried to create a block in the way you explained, but when I select 'Full HTML' and place the block on a certain page, it only displays the code itself, instead of 'reading' the code... How can I fix this?

share|improve this answer
 
Jeroen, I just tried 4life's advice. Worked perfectly. Select PHP as he instructs. The solution was so simple. –  user2398188 Jul 17 at 5:12

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.

share|improve this answer
 
The addthis module is for share buttons, not for follow us buttons. Perhaps I missed something. –  user2398188 Jul 17 at 3:50
 
Sorry, I've edited the answer to add the module for follow buttons. –  revagomes Jul 17 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. –  user2398188 Jul 17 at 21:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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