I currently have my homepage slider's image source setup like this: src="<?php the_field('slider_foto'); ?>"
which works great in my front-page.php.
the size of those images is 1600x500 px, which is great for large screen, but as soon as go below 767px viewport size the slider becomes small in width compared to the screensize.
Thus I would like the image source to change to src="<?php the_field('slider_foto_mobile'); ?>"
as soon as viewport width gets below 767px. I found this post that gives me a start: Change image source based on viewport width
But I can't figure out how to implement a predefined <?php the_field(); ?>
for the image src in the function.
Can anybody help me out with this?
Thanks!
EDIT 1
I found out I will be using Mobile Detect for this issue, however Im having issues implementing it. I copied the php file to the root of my theme, what do i need to do next? Do I need to include this in my functions.php:
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
Im stuck on what to do, I don't understand.
Do I need to call stuff like this in functions.php as well? $detect->isMobile();
$detect->isTablet();
and after that use this in my front-page.php? if ($detect->isMobile()) {}
?
Thanks! /EDIT 1
EDIT 2
I now have this is my front-page.php
because thats the only place I use it. I start my file with this:
<?php get_header(); ?>
<?php
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
?>
A little bit down the page I execute the following:
<?php if ( $detect->isMobile() && $detect->isTablet() ) { ?>
<img class="carousel-image" src="<?php the_field('slider_foto_mobile'); ?>" alt="<?php the_title(); ?>">
<?php } else { ?>
<img class="carousel-image" src="<?php the_field('slider_foto'); ?>" alt="<?php the_title(); ?>">
<?php } ?>
I works on iPad, it differentiates the src, but on the iPhone (and probably every other phone) it still shows the <?php the_field('slider_foto'); ?>
instead of the <?php the_field('slider_foto_mobile'); ?>
Again, it works on the tablet! whats the issue?
Thanks!
/EDIT 2