-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!

closed as too broad by kiamlaluno Nov 7 '16 at 20:38

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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

  • Thanks! Do you think it'll slow everything down to do it via the block? – deemeetree 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? – deemeetree 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.

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