Linking to a JS script

Hello,

I’m looking at using the srcset element in HTML code and I need to link to a picturefill polyfill JS script to ensure my site works with old browsers.

Is it possible to link to JS script or do I need to put the Javascript in the Javascript customizer? My concern with doing this is my understanding is it’s better to make the polyfill load asynchronously and I’m not clear if adding it to the customizer would violate that.

Hi,

You can add this in your child theme’s functions.php file

function add_this_script_footer(){ ?>

[YOUR JS CODE HERE]

<?php } 

add_action('wp_footer', 'add_this_script_footer');

Change [YOUR JS CODE HERE] with your js code

eg.

function add_this_script_footer(){ ?>

<script src="picturefill.min.js"></script>

<?php } 

add_action('wp_footer', 'add_this_script_footer');

Hope that helps.