How To Detect Mobile Using PHP

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

function is_mobile() {
    return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up.browser||webos|wos)/i", $_SERVER&#91;"HTTP_USER_AGENT"&#93;);

Then to call this function you need to do the following:

	// Non mobile content here
} else {
	// Mobile content here
Free Graphics, Icons, Tutorials
Free Graphics Free Christmas Vector Icon Graphics Pack 2017Free Fitness Vector Icons Graphics PackFree Camping Vector Graphics PackFree Summer Graphics PackFree File Icon PackFree Fast Food Vector Graphics
Sharing is caring...
Like & Follow
Share the love, share this page! Facebook Twitter Digg Reddit LinkedIn Pinterest Email
Close [X]
The Web Taylor
1000 Lakeside North Harbour Portsmouth, Hampshire PO6 3EN
02392 123358