i'm trying to add some html code to my php only if my window width is greater than 1024px. this is what i got so far...
$ScreenWidth = "<script type='text/javascript'>document.write(window.innerWidth);</script>";
if ( $ScreenWidth > 1024 ) {
echo 'Desktop';
} else {
echo 'Mobile';
}
but the problem is that $ScreenWidth is not returning a number,
echo $ScreenWidth
will return :
<script type="text/javascript">document.write(window.innerWidth);</script>2003
so i cannot use $ScreenWidth
if in PHP if condition.
can you guys give me a hint on how to fix this ? or i'll appreciate it if you could suggest a better way to write a PHP condition based on browser window with.
P.S: i do can hide or display none the content using css but as this html codes are loading images and videos i want to able to completely prevent loading them on mobile pages instead of loading and then hiding them using css.