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
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
WordPress doesn’t have any functionalities to detect window width. PHP itself cannot do that.
The most promising solution is to use wp_is_mobile():