[Resolved] Different hooks for mobile and desktop

Home Forums Support Different hooks for mobile and desktop

  • This topic has 5 replies, 2 voices, and was last updated 11 months ago by David.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1048470
    Sara

    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?

    #1048639
    David
    Staff
    Customer Support

    Hi there,

    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; ?>
    #1048643
    Sara

    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.

    #1048681
    David
    Staff
    Customer Support

    That function should detect ‘all’ mobile browsers regardless of the screen size so Tablets would be included.

    #1048685
    Sara

    Excellent. Thanks again!

    #1048691
    David
    Staff
    Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.