Is there a way to enable a hook just for mobile or just for desktop?
The reason I ask is that I’m using an external javascript for an opt-in lightbox. I want to use one script for desktop (which pops up on exit intent) and a different script for mobile (which pops up after a number of seconds).
If not – is there another to execute a javascript depending on what device the user is using?
You can try using the wp_is_mobile function to set the display conditions for the two different scripts like so:
<?php if ( wp_is_mobile() ) : ?>
/* Display and echo mobile specific stuff here */
<?php else : ?>
/* Display and echo desktop stuff here */
<?php endif; ?>
That is perfect! Thanks so much. Would the wp_is_mobile function also cover tablets? I just realized I want the first script to display for both mobile AND tablets.