-2

I'm trying to insert a JavaScript code on a specific page using Tracking Code Snippets module, but it does not seem to work (there's a bug in it). Specifically, I want the code to be inserted only on a specific page (URL path .html) inside the tag. Anyone knows of a module / easy solution (without changing the code of my .tpl files) to do that? Thanks!

  • Notice that requests for module are off-topic, and easy solution is rather subjective_. – kiamlaluno Nov 7 '16 at 20:39
2

You can place it in a block that only displays on that page.

If you want it in the head, there's a module that does it for you: Add To Head

| improve this answer | |
  • Thanks! Do you think it'll slow everything down to do it via the block? – Aerodynamika Nov 7 '16 at 19:53
  • As far as Drupal goes it shouldn't slow anything down. Mostly depends upon the Javascript. – Will Nov 7 '16 at 19:58
  • Ok, with the block it won't work because I don't have a setting in my theme to display it inside the <head> tag... Unless I didn't notice another way of doing it? – Aerodynamika Nov 7 '16 at 20:19
  • Blocks don't go in the head. If you need it in the head, you can use the module I mentioned or blu's answer. – Will Nov 7 '16 at 20:34
2

in your themes template.php you can add this to node preprocess:

function MY_THEME_preprocess_node(&$vars) {
    if($vars['nid'] == 'XX'){
      drupal_add_js('path/to/js/file.js');
    }
}

this checks for only node pages that match the node ID. you can also change drupal_add_js to have the javascript placed at the footer instead of header.

| improve this answer | |

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