Sitemdeki metinlerdeki her 12 paragraftan sonra reklam eklenmesini istiyorum, elimde hazır kod var düzenledim ama sonuç elde edemedim. Yardımcı olabilir misiniz?
require( get_template_directory() . '/app/theme.php' );
add_filter(‘the_content’, ‘madara_text_chapter_filter’);
function madara_text_chapter_filter($content){
$manga_id = get_the_ID();
$chapter_slug = get_query_var( ‘chapter’ );
$chapter_type = get_post_meta( $manga_id, ‘_wp_manga_chapter_type’, true );

/**
* First, we need to make sure this is the filter called from main content
**/

if($chapter_type == ‘text’){

$tag = preg_quote(‘p’);
preg_match_all('{<'.$tag.'[^>]*>(.*?)}', $content, $matches, PREG_PATTERN_ORDER);


if(count($matches[12]) > 0){
// now $matches[0] will have all paragraph in content
// this variable holds the index of the paragraph that you want to append the Ads
$paragraph_index = 12;
$ads_content = '<script></script>


<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>';

if(isset($matches[12][$paragraph_index])){
$content = str_replace($matches[12][$paragraph_index], $matches[12][$paragraph_index] . $ads_content, $content);
}
}
}

return $content;
}