DEV Community

Nick Young
Nick Young

Posted on

Checking for mobile in your template files

I am currently working on a site that makes heavy use of ACF Flexible COntent fields and it's great. We load a lot of things conditionally though and one of the sections is a hero section with a video background that auto-plays. This is great except for on mobile, which I received a request to have it use a background image instead of the video.

After a quick little search, I came across this function wp_is_mobile()
(https://developer.wordpress.org/reference/functions/wp_is_mobile/)

I had never heard of it before, but I figured it will work better than nothing and be quick to implement if it does work. Well, after my initial test it does work! Upon closer inspection the function is filterable too so as a developer we can add our own specific checks as well if we need it.

I thought this was pretty neat and so I wanted to share. What are some WP functions you have come across that aren't so well-known?

Top comments (0)