Check for mobile and redirect

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!