There is no doubt that mobile internet usage is soaring. This means that website owners must ensure that their websites are compatible with mobile devices. Many people are now choosing responsive web design as opposed to a separate mobile site. If this is the case, it is quite likely that you will have elements on your pages that you do not want to show on the responsive version. Rather than just hide this with CSS and bloat your page’s code, you can remove it completely with PHP using the following function:
Please note: this code has to be included on every page you need to call the function on. If you are using WordPress your functions.php file is ideal
<?php function is_mobile() { return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up.browser|up.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]); } ?>
Then to call this function you need to do the following:
<?php if(!is_mobile){ // Non mobile content here } else { // Mobile content here } ?>