Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding something to <head> on individual pages
#1
Is there a way to do this or perhaps a plugin that accomplishes it? I have a specific page on which I want to use a Javascript image gallery, but I don't want to link the script on all the pages, just the photo gallery.

I know I could create a second copy of the main template, but that's not very elegant (and now I'd have to make every change to the template twice).
Reply
#2
Yes, it would be possible. But it might be easier to just set up a custom field in the page editor, that way you have it in place for the future if you want to add anything to the HEADs of other pages.
“Don’t forget the important ˚ (not °) on the a,” says the Unicode lover.
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!
Reply
#3
Thanks for the suggestion. At first, I had all sorts of problems with escape characters showing up in the generated HTML, but then I realized I could just narrow it down to the link itself. I finally used this in the header:

Code:
<script language="javascript" src="<?php getCustomField('headerjs'); ?>"></script>

Not 100% elegant as it's extraneous markup on pages that don't use any JS, but it works.
Reply
#4
How about only adding the SCRIPT-element when the headerjs field for the page has actually been filled with something?
Code:
<?php
   if (strlen(returnCustomField('headerjs'))>0) {
      echo '<script language="javascript" src="'.returnCustomField('headerjs').'"></script>';
   }
?>
“Don’t forget the important ˚ (not °) on the a,” says the Unicode lover.
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!
Reply




Users browsing this thread: 1 Guest(s)