Add custom body_class using wp_is_mobile

The wp_is_mobile() function was not meant to be used for styling. However, if you need to add a body_class that will define specific styles for a mobile device, this snippet will add a class, called is-mobile, to the admin header. Just add this snippet to the functions.php file of your WordPress theme.

function wpsnipp_mobile_body_class( $classes ) {
	if ( wp_is_mobile() ) {
		$classes[] = 'is-mobile';
	return $classes;
add_filter( 'body_class', 'wpsnipp_mobile_body_class' );

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!