Check for mobile and redirect

image_pdfimage_print

So today I needed to send users on mobile devices to an external URL. That’s easy enough, but the client needed users headed to a different external URL if they were headed to one particular section of the site. In the code below, I use wp_is_mobile to test the browser; if true, then I check the page they’ve requested. If it’s that page or any of that page’s children, they’re redirected to one URL. If it’s mobile but not that page, they’re redirected to a different URL. Works perfectly!

stuff we dig

FYI: yes, the above are affiliate links, so we do make a small amount of money if you follow them over and buy what they're selling. Thank you for helping pay our hosting costs!

Dave Kuhar

Dave ran Transmit Studio, a media creation lab in San José. He's built more websites with WordPress than he can remember. He's reluctantly moved back to Ohio and now works for Stanford University (remotely). He likes hearing himself talk and writing about himself in third person.

Leave a Comment