Question

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?

Était-ce utile?

La solution

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;

} ?>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top