<?php
/*
Plugin Name: IADS
Description: Insert ads after the Xth paragraph.
Version: 1.1
Author: uyx
*/
add_filter('the_content', 'article_ad');
function article_ad($post_content) {
global $wp_query, $post;
if (!is_single() ) return $post_content;
// After which paragraph to insert the ad
$afterParagraph = 8; // insertar despues de X parrafo, o salto de linea dentro del contenido del post
// Adsense code
$adsense='<div class="bloquecito"> AQUI CODIGO ADSENSE </div>';
// $matches is an array of paragraph number and [1] character length
preg_match_all('/(?:\r\n|\r|\n)/', $post_content, $matches, PREG_OFFSET_CAPTURE );
$insert_at = $matches[0][$afterParagraph][1];
return substr($post_content,0,$insert_at). $adsense . substr($post_content,$insert_at,strlen($post_content));
}
?>