1

I would like to know is there any wordpress plugin or codes to detect the user using mobile/tablet and load some specific javascript?

I found online that there are some WP plugin to load theme when detected as mobile. But is there any way to load javascript rather than themes?

user3004356
  • 870
  • 4
  • 16
  • 49
Carson Lee
  • 2,673
  • 3
  • 20
  • 23
  • 1
    This seems relevant: http://stackoverflow.com/questions/7625718/how-to-use-javascript-conditionally-like-css3-media-queries-orientation – aroth Mar 18 '14 at 05:37

1 Answers1

2

You do not need an external plugin for something, which is already implemented in WordPress system.

You can use the wp_is_mobile(); conditional tag to check if the user is visiting using a mobile device. This is a boolean function, meaning it returns either TRUE or FALSE, you can place it in your header.php and then redirect the users to the proper content.

<?php if ( wp_is_mobile() ) {
    /* Display and echo mobile specific stuff or redirect here */
  wp_redirect( $location, $status );
  exit;

} ?>
Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52