To customise the number of paragraphs before the featured image, I adapted the above answer and adapted the code from an ad placement solution.
To use: Add the following two snippets to functions.php and customise the numeral where indicated to control the number of paragraphs.
// Adds $featured_img and $caption after n paragraph
add_filter( 'the_content', 'insert_featured_image' );
function insert_featured_image( $content ) {
if ( has_post_thumbnail($post->ID) ) {
if ( has_post_thumbnail($post->ID) ) {
$caption = get_the_post_thumbnail_caption( $post );
} else {
$caption = '';
}
$featured_image = '<div>' . get_the_post_thumbnail( $post->ID, 'full' ) . '</div>'.'<div>' . $caption . '</div>';
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $featured_image, 2, $content ); // The numeral here controls the number of pars. Customise it to your needs
}
}
return $content;
}
// Parent function
function prefix_insert_after_paragraph( $insertion, $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] .= $insertion;
}
}
return implode( '', $paragraphs );
}