I'm wanting to echo
some code based on whether the user is on a mobile device (less than 768px) or larger.
I have done the following:
<?php
if ( is_home() ) {
?>
<script type="text/javascript">
if ($(window).width() < 768) {
document.write("<?php echo my_shortcode("[mobile-slider]"); ?>");
} else {
document.write("<?php echo my_shortcode("[desktop-slider]"); ?>");
}
</script>
<?php
} else {
//do the stuff for the other pages
} ?>
But now when the homepage renders it displays "); } else { document.write("
then the homepage slider and then "); }
. Any idea why?
JS error
SyntaxError: unterminated string literal
document.write('
HTML Output - Seems to be adding a line break which I think is breaking the script?
<script type="text/javascript">
if ($(window).width() < 768) {
document.write("
<!--slider-->