Can anyone recommend a module that will allow me to add code to the section of an individual page (not the whole theme)?

Or, if not, is there an easy way to access and edit the underlying code of an individual page?

Thank you.

Comments

yelvington’s picture

dmisaacson’s picture

Ah, great! Thank you! The js injector might be just the thing (as long as it can inject on a single page and not the whole theme).

The code is a bit of code to track a Facebook ad... specifically

(function() { var _fbq = window._fbq || (window._fbq = []); if (!_fbq.loaded) { var fbds = document.createElement('script'); fbds.async = true; fbds.src = '//connect.facebook.net/en_US/fbds.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(fbds, s); _fbq.loaded = true; } })(); window._fbq = window._fbq || []; window._fbq.push(['track', '6030525796975', {'value':'0.00','currency':'USD'}]);

Only local images are allowed.

dmisaacson’s picture

Thank you! I think js_injector might be just the thing. Do you know if it works for specific pages, or for the whole theme?

The code I want to put in the head is a script to track a FB ad... specifically:

<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', '6030525796975', {'value':'0.00','currency':'USD'}]);
</script>
<noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?ev=6030525796975&amp;cd[value]=0.00&amp;cd[currency]=USD&amp;noscript=1" /></noscript>
devtherock’s picture

And if you are looking to add meta tags for few nodes try this https://www.drupal.org/project/metatag

cmsMinds’s picture

Hello,

Instead of using module, you can create a custom js file for your code
and specify the path for the specific page you want to use.
for example if you just want to use this code only for front page then,
the example given below will guide you to do so..
I hope it may help you somehow.

you need to include this code into your template.php file at the bottom.

/**
* Add javascript files for front-page jquery slideshow.
*/
if (drupal_is_front_page()) {
drupal_add_js(drupal_get_path('theme', 'your theme name') . '/js/jquery.flexslider.js');

}
]

ashish.mahajan’s picture

try add to head module
https://www.drupal.org/project/add_to_head

You can add css and js and can associate the code with the page of your choice!!!

susanmoulton’s picture

I have been using the CSS and JS injectors successfully, however, I haven't figured out how to (as an editor) add links in head tag... specifically hreflang, for a handful of nodes. Any advice?

ProRB’s picture

/admin/config/development/add-to-head/name-of-individual-add-to-head-profile

<link rel="alternate" href="https://site-name.extension/page" hreflang="en-us" />
<link rel="alternate" href="https://site-name.extension/page-for-canada" hreflang="en-ca" />
<link rel="alternate" href="https://site-name.extension/page-for-undeclared-region-english" hreflang="en" />
<link rel="alternate" href="https://site-name.extension/page-for-no-language-declared" hreflang="x-default" />

[x] Show only on the listed pages

*page-goes-here*

For what it is worth, the link/hreflang code above passes hreflang checkers like this: https://technicalseo.com/tools/hreflang/