アドセンス広告を移動させたら、収益が120倍になった話
まいどおおきに!おおもと(@so88qa)です
今回の記事はぼくがメインブログでやっているアドセンスのCSSをただ書くだけの話。
参考ブログ
まず【functions.php】
記事内広告をh2タグに一個飛ばしで配置してます。
cssはこちら
// 本文中にアドセンス表示
function add_ads_before_h2($the_content) {
if (is_single()) {
$ads = <<< EOF
<div style="text-align:center">スポンサーリンク</div>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:block; text-align:center;"
data-ad-layout="in-article"
data-ad-format="fluid"
data-ad-client="ca-pub-ユーザー番号"
data-ad-slot="ユーザー番号"></ins>
<script>
(adsbygoogle = window.adsbygoogle || ).push({});
</script>
<amp-ad width="100vw" height=320
type="adsense"
data-ad-client="ca-pub-ユーザー番号"
data-ad-slot="ユーザー番号"
data-auto-format="rspv"
data-full-width>
<div overflow></div>
</amp-ad>
<div style="clear:both"></div>
EOF;
$h2 = '/^.+?<\/h2>$/im';//H2見出しのパターン
if ( preg_match_all( $h2, $the_content, $h2s )) {
if ( $h2s[0] ) {
// 3つ目のh2見出しの上にアドセンス挿入
if ( $h2s[0][2] ) {
$the_content =
str_replace($h2s[0][2], $ads.$h2s[0][2],
$the_content);
}
// 5つ目のh2見出しの上にアドセンス挿入
if ( $h2s[0][4] ) {
$the_content =
str_replace($h2s[0][4], $ads.$h2s[0][4], $the_content);
}
// 7つ目のh2見出しの上にアドセンス挿入
if ( $h2s[0][6] ) {
$the_content =
str_replace($h2s[0][6], $ads.$h2s[0][6], $the_content);
}
// 9つ目のh2見出しの上にアドセンス挿入
if ( $h2s[0][6] ) {
$the_content =
str_replace($h2s[0][8], $ads.$h2s[0][8], $the_content);
}
// 11つ目のh2見出しの上にアドセンス挿入
if ( $h2s[0][6] ) {
$the_content =
str_replace($h2s[0][10], $ads.$h2s[0][10], $the_content);
}
}
}
}
return $the_content;
}
add_filter('the_content','add_ads_before_h2');
次にCoccon(コクーン)の【tmp-user/main-before.php】で「ヘッダー」と「メインカラム」の間にバーナー広告を表示してます。もちろんPC・スマホ・AMPはそれぞれ表示するように工夫
<div style="text-align: center;margin-top: 28px;"><div style="text-align: center;margin-top: 28px;">
<?php if (!wp_is_mobile()) :?>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ビックバーナー -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-ユーザー番号"
data-ad-slot="ユーザー番号"></ins>
<script>
(adsbygoogle = window.adsbygoogle || ).push({});
</script>
<?php endif; ?>
</div>
<div style="text-align: center;">
<?php if (wp_is_mobile()) :?>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- ラージモバイルバーナー -->
<ins class="adsbygoogle"
style="display:inline-block;width:320px;height:100px"
data-ad-client="ca-pub-ユーザー番号"
data-ad-slot="ユーザー番号"></ins>
<script>(
adsbygoogle = window.adsbygoogle || []).push({});
</script>
<?php endif; ?>
</div>
<div style="text-align: center;">
<amp-ad width="100vw" height=320
type="adsense"
data-ad-client="ca-pub-ユーザー番号"
data-ad-slot="ユーザー番号"
data-auto-format="rspv"
data-full-width>
<div overflow></div>
</amp-ad>
</div>