Wordpress - Proper usage of wp_is_mobile()?
In very layman term wp_is_mobile()
is not for styling your theme.
How it works:
It matches some of device's native name in User Agent String. So if someone manipulate the string and send false information you can not detect what device it is.
And it does not return any device name it just return true
if you are on not on desktop else false
How WordPress use it: WordPress do not use it for styling or adding CSS anywhere. WordPress use it to add or manipulate thing which should be only on mobile devices (regardless size and name.) e.g. to add touch scripts, add viewport, mobile class in admin header, adding mobile buttons.
Effect of caching: If you use caching plugin it is useless. As your code not executed every time so you get the same result every time.
WordPress mostly use it at back-end and almost every caching plugin excludes caching at back-end or say for logged-in user. So it works fine.
wp_is_mobile()
detects device based on HTTP USER AGENT
(it's not related to screen size)
wp_is_mobile
return true or false based on $_SERVER['HTTP_USER_AGENT']
if $_SERVER['HTTP_USER_AGENT']
contains Mobile( Android, IOS ... ) its returns true
else return false
for more info check function source code