Wordpress 如何在genesis中仅在第一段之后添加adsense代码?

Wordpress 如何在genesis中仅在第一段之后添加adsense代码?,wordpress,genesis,Wordpress,Genesis,我只想在第一段之后显示adsense广告。有人能用正确的代码指导我吗。如果你愿意使用插件,你可以使用插入贴子广告 下面是一个如何设置它的快速教程:您可以使用以下代码手动完成。它的效率非常高,速度也非常快: add_filter('the_content', 'prefix_process_content', 20); function prefix_process_content($content){ $needle = '</p>'; $replace= '</p>

我只想在第一段之后显示adsense广告。有人能用正确的代码指导我吗。

如果你愿意使用插件,你可以使用
插入贴子广告


下面是一个如何设置它的快速教程:

您可以使用以下代码手动完成。它的效率非常高,速度也非常快:

add_filter('the_content', 'prefix_process_content', 20);

function prefix_process_content($content){

$needle = '</p>';

$replace= '</p>your ad code here'; // do not forget the </p>

// Get the position of the first occurrence of $needle
$pos = strpos($content, $needle);

// if found
if ($pos !== false) {
    $newstring = substr_replace($content, $replace, $pos, strlen($needle));
}

return $newstring;

}
add_filter('the_content','prefix_process_content',20);
函数前缀\u进程\u内容($content){
$Pinele='

'; $replace='

此处的广告代码';//不要忘记

//获取$pinder第一次出现的位置 $pos=strpos($content,$needle); //如果找到 如果($pos!==false){ $newstring=substr_replace($content,$replace,$pos,strlen($needle)); } 返回$newstring; }
我没有测试它,但应该可以工作。如果你需要代码方面的帮助,请告诉我

如果您使用的是WordPress,您可以使用一个插件,它可以像
WP QUADS
那样实现这一点。它只会增加很少的开销,并且不会增加站点的加载时间

它的维护和测试与最新的WordPress版本


免责声明:我是插件的作者

无需插件