我想在段落之前添加广告。我怎么能这样做?
此代码在段落后添加广告。
add_filter( 'the_content', 'ads_after_paragraphs');
function ads_after_paragraphs( $content ) {
$adsafterparagraph = array(1,5,10,15);
global $post;
$ad = 'ADS CODE';
$content_expl = explode("</p>", $content);
for ($i = 0; $i <count($content_expl); $i++ ) {
if (in_array($i, $adsafterparagraph)){
$content_expl[$i] = $content_expl[$i].$ad;
}
}
return implode("</p>", $content_expl);
}