How do I insert Javascript before the closing body tag?

Hi, my client has asked me to insert some Javascript which enables him to be verified for an affiliate scheme that he has joined. The company who he has become an affiliate for has asked him to insert some javascript before the closing body tag of his site’s template.

The code looks like this:

<script type="text/javascript">
var vglnk = {key: '5643e4a94bhdstswd0add591eb68sh8tw8h'};
(function(d, t) {
var s = d.createElement(t);s.type = 'text/javascript';
s.async = true;s.src = '//cdn.viglink.com/api/vglnk.js';
var r = d.getElementsByTagName(t)[0];
r.parentNode.insertBefore(s, r);
}(document, 'script'));
</script>

Can I simply add it to the Global JS in the Theme options? Or do I need to add it to the Child theme’s function.php file. If it needs to go in the function.php file, what is the accompanying code that I require in order to insert the javascript?

Many Thanks
Lewis

Hi Lewis,

Thank you for writing in, you can use the plugin Insert Headers and Footers.

The Footer is the before closing </body> tag area.

Hope it helps,
Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.