• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.2 Where is the best place to add a script?

Stuart Wright

Well-known member
#1
I want to add this script into Xenforo. Probably near the end.
if (!Modernizr.svg) {
$('img[src$=".svg"]').each(function()
{
$(this).attr('src', $(this).attr('src').replace('.svg', '.png'));
});
}
It swaps out SVGs with PNGs for browsers which don't support SVGs.
It uses the Modernizer javascript which I included in the PAGE_CONTAINER template.
I have popped the above code at the end of page_container_js_body, but I'm expecting there is a better way to do this. Like in a hook or something?
Thanks
 

Teapot

Well-known member
#2
Generally, unless you're planning to put it in its own JavaScript file, the page_container_js_body template is the best place to put it in my opinion.
 

Brogan

XenForo moderator
Staff member
#3
The FAQ in my signature explains where to add it, depending on the requirements of the script.