Enqueue script if screen is greater than 500

i need to call a javascript only if screen resolution is greater than 500.

I found below code…

<script type='text/javascript' src='<?php echo $urlPlugin?>js/jquery.themepunch.revolution.min.js?rev=<?php echo RevSliderGlobals::SLIDER_REVISION; ?>'></script>

So, i modified it as below…

if (window.innerWidth > 500) {
    var head = document.getElementsByTagName('head')[0];

    var s1 = document.createElement("script");
    s1.type = "text/javascript";
    s1.src = "http://domain.com/wp-content/plugins/revslider/public/assets/js/jquery.themepunch.revolution.min.js";

However that did not work.

Later i came to know about enqueue function. i have lines as following…

wp_enqueue_script('revmin', RS_PLUGIN_URL .'public/assets/js/jquery.themepunch.revolution.min.js', 'tp-tools', $slver, $ft);

this function auto-calls scripts. so, how do i make it conditional??

Read more here: Enqueue script if screen is greater than 500

Leave a Reply

Your email address will not be published. Required fields are marked *