2014-10-10 34 views
0
  • WordPress主题选项面板。
  • 用户输入无响应的AdSense代码的textarea字段。

我需要,如果用户输入一个非响应AdSense代码,该代码可以在响应代码转换为:如何使用preg_match自动转换自适应广告中的常规Google AdSense广告?

NON REPONSIVE CODE:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> 
<!-- non responsive ads --> 
<ins class="adsbygoogle" 
    style="display:inline-block;width:728px;height:90px" 
    data-ad-client="ca-pub-12345" 
    data-ad-slot="xxxxxxxxxxxxxx"></ins> 
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script> 

上面的代码需要转换的:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> 
<ins class="adsbygoogle" 
style="display:block" 
data-ad-client="ca-pub-12345" 
data-ad-slot="xxxxxxxxxxxxxx" 
data-ad-format="auto"></ins> 
<script> 
(adsbygoogle = window.adsbygoogle || []).push({}); 
</script> 

我猜这项工作可以用preg_match完成,但是怎么做?

谢谢。

+1

如何为'.adsbygoogle'添加css规则? – Cerbrus 2014-10-10 13:35:10

+0

有趣。日Thnx – 2014-10-10 13:38:14

回答

0

你不能这样做(据我所知)。

这(无响应)单元配置存储在谷歌服务器上:

{ 
    "status": "ACTIVE", 
    "kind": "adsense#adUnit", 
    "code": "xxxxxxxxxxxxxx", 
    "name": "non responsive ads", 
    "savedStyleId": "qwertzuiopšđžasdfghjklyxcvbnmqwerfvbgtzhnmjgbvfredcxsw", 
    "contentAdsSettings": { 
    "type": "TEXT_IMAGE", 
    "backupOption": { 
     "type": "BLANK" 
    }, 
    "size": "SIZE_728_90" 
    }, 
    "id": "ca-pub-12345:xxxxxxxxxxxxxx" 
} 

pagead2.googlesyndication.com会考虑data-ad-slot="xxxxxxxxxxxxxx"广告请求的请求SIZE_728_90格式,你不能改变的“即时” - 如果您需要另一个广告单元size,则需要创建另一个广告单元。

即使您会这么做,它看起来像“有效”,但仍然违反了AdSense政策,并且会对您所在网站上涉及的所有AdSense帐户和广告投放构成风险。 (因为“转换”的代码会让你的无效广告展示的一些百分比,和/或错误的请求。)

修改AdSense广告代码的
https://support.google.com/adsense/answer/1354736?hl=en

创建自适应广告单元
https://support.google.com/adsense/answer/3543893?hl=en

相关问题