Cocoonの「adsbygoogle.push() error: No slot size for availableWidth=0」エラー対応案
function get_normal_adsense_responsive_code($format = DATA_AD_FORMAT_AUTO, $code = null){ | |
//$codeに広告コードが入っている場合はそこから取得する(無い場合はテーマ設定のAdSenseコードを利用) | |
if (get_adsense_ids($code)) { | |
$data_ad_layout = null; | |
//フォーマットが設定されていない場合はフォーマットをコード内から取得 | |
if ($format == 'none') { | |
if (preg_match('{data-ad-format="([^"]+?)"}i', $code, $m)) { | |
if (isset($m[1])) { | |
$format = $m[1]; | |
} | |
} | |
} | |
//記事内広告の場合は付け加える | |
if ($format == DATA_AD_FORMAT_FLUID) { | |
$data_ad_layout = ' data-ad-layout="in-article"'; | |
} | |
return | |
'<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> | |
<!-- レスポンシブコード --> | |
<ins class="adsbygoogle" | |
style="display:block" | |
data-ad-client="'.get_adsense_data_ad_client($code).'" | |
data-ad-slot="'.get_adsense_data_ad_slot($code).'"'. | |
$data_ad_layout.' | |
data-ad-format="'.$format.'"></ins> | |
<script> | |
window.onload = function() { | |
(adsbygoogle = window.adsbygoogle || []).push({}); | |
} | |
</script>'; | |
} | |
//コードが設定されていない場合はそのままコードを出力する | |
return $code; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment