Posts: 10
Threads: 3
Joined: Feb 2010
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).
Posts: 972
Threads: 27
Joined: Aug 2009
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.
Posts: 10
Threads: 3
Joined: Feb 2010
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.
Posts: 972
Threads: 27
Joined: Aug 2009
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>';
}
?>