[WordPress 用] レスポンシブデザインというか PC とスマートフォンで同一ソースにしているサイトで、PC からのアクセスのときだけ Facebook のコメントボックスを表示するサンプル。スマートフォン用のコメントボックスは何か異常に大きな余白ができるし、ケータイから書く人少なそうだし、もういっそ非表示にしちゃおう!と言ってみるテストも兼ねて。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- コメントボックスを表示したいところにこれを置く --> | |
<script> | |
(function(){ | |
var ua = navigator.userAgent; | |
if (ua.indexOf('iPhone') == -1 | |
&& ua.indexOf('iPad') == -1 | |
&& ua.indexOf('iPod') == -1 | |
&& ua.indexOf('Android') == -1) { | |
document.write('<div class="fb-comments" data-href="<?php the_permalink(); ?>" data-num-posts="10"></div>'); | |
} | |
})(); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
こっちは Facebook で指定されたコード。<body> 開始タグの直後に。 | |
***** のところは自分のアプリケーション ID に置き換えてください。 | |
詳細はこちら https://developers.facebook.com/docs/reference/plugins/comments/ | |
--> | |
<div id="fb-root"></div> | |
<script>(function(d, s, id) { | |
var js, fjs = d.getElementsByTagName(s)[0]; | |
if (d.getElementById(id)) return; | |
js = d.createElement(s); js.id = id; | |
js.src = "//connect.facebook.net/ja_JP/all.js#xfbml=1&appId=*****"; | |
fjs.parentNode.insertBefore(js, fjs); | |
}(document, 'script', 'facebook-jssdk'));</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment