WordPress: Show Featured Image after First Paragraph

Most of the WordPress themes let you control where to show/display the featured posts. But most of the times the option is limited to above the post title or below the post title.

If you want to display the featured image after the first paragraph of your post content, you can use this code:

add_filter( 'the_content', 'insert_featured_image', 20 );

function insert_featured_image( $content ) {

    $content = preg_replace( "/<\/p>/", "</p>" . get_the_post_thumbnail($post->ID, 'post-single'), $content, 1 );
    return $content;
}
PHP

How to add this code to your WordPress site

Leave a Comment