How to display responsively sized images via php?

I have some custom sized images set up through ACF and functions.php

    add_image_size('recipe-landscape', 400, 260, true);
    add_image_size('recipe-portrait', 260, 100, true);

What I want to do i display the landscape one on larger devices and the portrait on phones. I know how to do that with CSS media queries but it's a php function

 <div class="single-img-container"> <img class="single-image" src="<?php echo the_post_thumbnail_url('recipe-landscape'); ?>" alt="<?php the_title(); ?>"></div>

Chat gpt says I can use if(wp_is_mobile() { portrait} else {landscape} the documentation is pretty light on the matter, anyone have insights or opinions?

1 Comment

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer