Domanda

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?

È stato utile?

Soluzione

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;

} ?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top