Site icon ROVINDO

pasang iklan atau new modoil tengah artikel

wp only

//Insert ads after second paragraph of single post content.
function prefix_insert_after_paragraph2( $ads, $content ) {
if ( ! is_array( $ads ) ) {
return $content;
}

$closing_p = ‘

‘;
$paragraphs = explode( $closing_p, $content );

foreach ($paragraphs as $index => $paragraph) {
if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $closing_p;
}

$n = $index + 1;
if ( isset( $ads[ $n ] ) ) {
$paragraphs[$index] .= $ads[ $n ];
}
}

return implode( ”, $paragraphs );
}

add_filter( ‘the_content’, ‘prefix_insert_post_ads’ );
function prefix_insert_post_ads( $content ) {
if ( is_single() && ! is_admin() ) {
$content = prefix_insert_after_paragraph2( array(
// The format is: ‘{PARAGRAPH_NUMBER}’ => ‘AD_CODE’,
‘1’ => ‘[dfads params=”groups=88″]’,
‘2’ => ‘



‘,
), $content );
}

return $content;
}

Exit mobile version