Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By dmisaacson on
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
What code?
What code?
https://www.drupal.org/project/js_injector and https://www.drupal.org/project/css_injector handle most use cases.
Ah, great! Thank you! The js
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'}]);Thank you! I think js
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:
And if looking..
And if you are looking to add meta tags for few nodes try this https://www.drupal.org/project/metatag
Hello,
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');
}
]
Raj Laddha
cmsMinds
rajesh@cmsminds.com
Drupal Development - North Carolina
Add to Head Module
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!!!
links in head section
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?
This is how I implmented hreflang:
/admin/config/development/add-to-head/name-of-individual-add-to-head-profile
[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/