How to Add JavaScript Code to Drupal Block

The Drupal block editor lets you manage and create custom blocks. Both the plain text and full HTML text filters strip out JavaScript code, which prevents JavaScript from being displayed on the live site. Fortunately, Drupal comes with a core module known as the "PHP Filter." By enabling this module, you can use Drupal blocks to insert JavaScript, such as the JavaScript snippet for a Google AdSense code.

Instructions

    • 1

      Click on the "Modules" menu link in the Drupal administration section.

    • 2

      Scroll down until you find the "PHP Filter" module. Check the box next to it. Click "Save."

    • 3

      Click on "Structure," then "Blocks." Select "Add New Block," or click on "Edit" next to the block where you want to add the JavaScript.

    • 4

      Select "PHP" beneath the Body box, then paste or type the JavaScript code into the box. Click on "Save Block."

Related Searches:

Resources

Comments

Related Ads

Featured