Created
October 15, 2018 13:36
-
-
Save ksakae1216/151c4edf5323d266a5443b062d22cb75 to your computer and use it in GitHub Desktop.
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 async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> | |
<script> | |
(function(){ | |
var adsScript = document.createElement("script"); | |
adsScript.innerHTML = "(adsbygoogle = window.adsbygoogle || []).push({});"; | |
// 以下それぞれ個別のデータを設定する | |
var key = "AAAAAAAAAAAAAAAAA" | |
var google_ad_client = "BBBBBBBBBBBBBBBBBBBBBB"; | |
var slot ="CCCCCCCCCC" | |
// ここまで | |
var adsDiv = document.createElement("div"); | |
adsDiv.innerHTML = '<ins class="adsbygoogle" style="display:block" data-ad-client="' | |
+ google_ad_client + '" data-ad-slot="' | |
+ slot + '" data-ad-format="fluid" data-ad-layout-key="' | |
+ key + '"></ins>'; | |
adsDiv.appendChild(adsScript); | |
// css 設定用 | |
adsDiv.classList.add("ads-infeed"); | |
// 記事一覧ページの場合 | |
// トップページなら page-index | |
if(document.body.classList.contains("page-archive")){ | |
var parentElement =document.getElementsByClassName("archive-entries")[0]; | |
var j = parentElement.childElementCount; | |
// 5記事おきに入れる場合 | |
for(var i=5; i<j; i=i+6) { | |
parentElement.insertBefore(adsDiv.cloneNode(true), parentElement.children[i]); | |
j++; | |
} | |
} | |
}()); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment