Is there a way to do an @if statement to determine if the user is on a mobile phone?

I am trying to know if there is a way to do an if statement so you can use one ACF with a mobile size image and an ACF for desktop users.

@IF(usersscreen < 764px)  // if true

    //use this  small image
  //use this instead

I don’t believe HTTP headers report device resolution, so I don’t think you can do that. In any event, you shouldn’t do it: Issues relating to screen size, pixel density, etc, should be pushed out to the browser, which has much better awareness of those things than the server. I strongly recommend reading up on responsive image techniques, which will allow you to accomplish what you’re looking to do in a better way. If you want to load completely different images based on screen properties, I’d recommend looking at the <picture> element specifically.

1 Like

You can you this library

Use this wordpress function: wp_is_mobile()

Careful, this won’t work whatsoever if your site is cached (which it should be!)

This topic was automatically closed after 42 days. New replies are no longer allowed.