Open new tab on link in computer but not in mobile

I´m currently working on a wordpress project and got in to some trouble.

I want to open a new tab with a page when users click on a link but only on computers. I found the following code for mobile detection:

Read More

<?php wp_is_mobile(); ?>

The reason I dont want the new link to open in a new tab on mobile is the fact that it opens “in front” of the other (my) page. This link contains a tracking cookie and thats why I need to get the visitor to open it.

How do I implement this code and prevent the mobile agent from opening new tabs?

Regards

Joel

Related posts

2 comments

  1. If you were to use the wp_is_mobile()-function, that could look something like:

    <?php
    if ( wp_is_mobile() ) {
        echo '<a href="link">Click here</a>';
    } else {
        echo '<a href="link" target="_blank">Click here pop-up</a>';
    }
    ?>
    
  2. <a href="..." target="<?=wp_is_mobile()?'_self':'_blank'?>">
    

    Not sure if it’s correct syntax but idea should be clear.

Comments are closed.