Adding “Media query” to If/else statements in PHP

Im using the following code to echo content in wordpress based on the size of its title.

<?php 
$title  = the_title('','',false);
if(strlen($title) > 35):
    echo content(20);
else:
    echo content(45);
endif;
?>

Is there a simple way of projecting a media query before this to echo an output based on the window width so basically for mobiles and devices

Read More

As per a reply i still cant get this to work using:

<?php 
if ( wp_is_mobile() ) {
    echo content (20);
} else {
$title  = the_title('','',false);
if(strlen($title) > 35):
    echo content(20);
else:
    echo content(45);
endif;
}
?>

Even simplifying the code to following doesn’t seem to work:

<?php 
if ( wp_is_mobile() ) {
    echo content(20);
} else {
    echo content(45);
}
?>

and simply uses the “else” value: echo content(45) on mobile

Related posts

Leave a Reply

1 comment