Here is the function I use to add a widget after the second paragraph in a post. This is only for the first post and single posts, so you will need to tweak it a bit if you need to show this in all posts. You should be able to modify this to suit your needs. Hope this helps
// Add advertising widget within the firts post and single posts
function pietergoosen_insert_content_after_second_paragraph_filter( $content ) {
static $first;
$first = (!isset($first)) ? true : false;
if (true == $first) {
ob_start();
echo '<div class="widget-box">';
dynamic_sidebar( 'sidebar-19' );
echo '</div><!-- end .widget-box -->';
$new_content = ob_get_clean();
if ( ! is_admin() ) {
return pietergoosen_insert_content_after_second_paragraph( $new_content, 2, $content );
}
}
return $content;
}
add_filter('the_content','pietergoosen_insert_content_after_second_paragraph_filter');
// Paragraph explode and insert
function pietergoosen_insert_content_after_second_paragraph( $new_content, $paragraph_id, $content ) {
$closing_p = '</p>';
$paragraphs = explode( $closing_p, $content );
foreach ($paragraphs as $index => $paragraph) {
if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $closing_p;
}
if ( $paragraph_id == $index + 1 ) {
$paragraphs[$index] .= $new_content;
}
}
return implode( '', $paragraphs );
}