Created
March 30, 2020 11:46
-
-
Save Apollojustice2/c521c9b25723c24a1cbb09f4c82710f8 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