WordPress Mobile Detection

WordPress offers since version 3.4 the function wp_is_mobile() with which you can determine mobile visitor. If you don’t use a Web-Framework, which brings with it a mobile detection, you can use WordPress with wp_is_mobile() to determine the mobile visitor and add a CSS class to the,. With the css class in the we can adjust the CSS for mobile visitor.

Add a CSS class to the body tag

We use the WordPress function add_filter() and extend the body_class() with the CSS class is-mobile for mobile visitor and with is-desktop for the desktop visitor.

add_filter('body_class', function($classes = '')
$classes[] = (wp_is_mobile())?'is-mobile':'is-desktop';
return $classes;
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn