This code add ads in the content. I want to change the output. I added new details. I tried on it but I could not solve the problem.
add_filter( 'the_content', 'ads_paragraphs');
function ads_paragraphs( $content ) {
$adsbeforeparagraph = array(1,3,5);
global $post;
$ad = 'ADS CODE';
$content_expl = explode("<p>", $content);
for ($i = 0; $i <count($content_expl); $i++ ) {
if (in_array($i, $adsbeforeparagraph)){
$content_expl[$i] = $ad . $content_expl[$i];
}
}
return implode("<p>", $content_expl);
}
input is here:
<p>text text text</p>
<p>text text text</p>
<p>text text text</p>
<p>text text text</p>
<p>text text text</p>
<p>text text text</p>
output is here:
<p>ADS CODEtext text text</p>
<p>text text text</p>
<p>ADS CODEtext text text</p>
<p>text text text</p>
<p>ADS CODEtext text text</p>
<p>text text text</p>
I want this output:
ADS CODE<p>text text text</p>
<p>text text text</p>
ADS CODE<p>text text text</p>
<p>text text text</p>
ADS CODE<p>text text text</p>
<p>text text text</p>