Adding ads after a certain number of paragraphs within Genesis themework
I am so close I can feel it. I am trying to get an ad block to show up after say 2 paragraphs. Currently I am using the following code in my functions.php to put the adblock before the last paragraph.
I cannot for the life of me find the correct code to get this done.
function ads_added_above_last_p($text) {
if( is_single() ) :
$ads_text = 'div class="wpselect_middle_content"My Ad Code Here/div';
if($pos1 = strrpos($text, 'p')){
$text1 = substr($text, 0, $pos1);
$text2 = substr($text, $pos1);
$text = $text1 . $ads_text . $text2;
}
endif;
return $text;
}
add_filter('the_content', 'ads_added_above_last_p');
If I play with the second $text string and put $pos2 it works perfectly BUT it duplicates all of the text within the post.
Any help would be greatly appreciated.
Topic adsense genesis-theme-framework Wordpress
Category Web