DEV Community

Nick Young
Nick Young

Posted on

2

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?

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay