echo
ユーザーがモバイル デバイス (768px 未満) を使用しているか、それより大きいかどうかに基づいて、いくつかのコードを作成したいと考えています。
私は次のことをしました:
<?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
} ?>
しかし、ホームページがレンダリングされると"); } else { document.write("
、ホームページのスライダーが表示され、次に"); }
. 理由はありますか?
JSエラー
SyntaxError: 終了していない文字列リテラル
document.write('
HTML 出力 - スクリプトを壊していると思われる改行を追加しているようですか?
<script type="text/javascript">
if ($(window).width() < 768) {
document.write("
<!--slider-->