I’m trying to add js files to WordPress footer id page width is larger than
<?php if(is_home()){ ?>
<script type="text/javascript">
$(document).ready(function(){
var wid = $(window).width();
if(wid>970){
<?=
'<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/script.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/slider.js"></script>'
?>
}
});
</script>
<?php } ?>
I’ve tried using .append() but sure I’m facing the same problem and it doesn’t add the files because the script code contains double quotes and single quotes while it’s wrapped in a single quote
You’ll need to add the code to inject tag into the HTML, do it by this:
It checks page’s width, according to that, select the script’s name then inject is to the end of the body.
What if you try to include the js file in js like this :