Skip to content

Instantly share code, notes, and snippets.

@ksakae1216 ksakae1216/adsence2
Created Oct 15, 2018

Embed
What would you like to do?
<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
You can’t perform that action at this time.