I need a option so that when I am adding some script using wp_enqueue_script it should load for specific screen size. Like when the screen size will be below 768px the script will not load.

I am using something like this for now.....

        wp_enqueue_style( 'wpm_animation_css', get_template_directory_uri() . '/assets/css/animation.css', array(), '1.1', false );
        wp_enqueue_script( 'uikit.min', get_template_directory_uri() . '/assets/js/uikit.min.js', array( 'jquery' ), '2.4.0', true );

Any help will be really appreciated.

Thanks Sabbir

  • 2
    PHP can't tell what the size of a screen is beforehand. Detecting mobiles also falls apart when you consider that browser windows can be resized. What you're trying to do will also fail when you deploy caching plugins
    – Tom J Nowell
    Commented Jul 23, 2014 at 21:58

1 Answer 1


At this point I can not think of a way to do what you ask in php (maybe in javascript), but perhaps approaching the problem differently, can serve you detect the mobile device in a better way using mobile-detect[1], wp_is_mobile() as it is very basic, only detects if mobile, but does not distinguish between phones or tablets.

And there is already a plugin for wordpress[2], and this library have a lot examples[3]

  1. https://github.com/serbanghita/Mobile-Detect
  2. http://wordpress.org/plugins/wp-mobile-detect/
  3. https://github.com/serbanghita/Mobile-Detect/wiki/Code-examples

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.