如何添加adsense代码后第1段仅在起源



我只想在第一段后面显示广告。请给我一个正确的代码好吗。

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

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;
}

我没有测试它,但应该可以工作。如果你需要代码方面的帮助,请告诉我。

如果你正在使用WordPress,你可以使用一个插件,它可以像WP QUADS一样做到这一点。它只会增加很少的开销,不会增加网站的加载时间。https://wordpress.org/plugins/quick-adsense-reloaded/

它使用最新的WordPress版本进行维护和测试!

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

如果您愿意使用插件,可以使用Insert Post Adshttps://wordpress.org/plugins/insert-post-ads/

下面是如何设置它的快速教程:http://www.wpbeginner.com/wp-tutorials/how-to-insert-ads-within-your-post-content-in-wordpress/

最新更新