My problem:
I’m trying to create a filter that will add the featured image of a post to the_content, so that I can have the first paragraph of the_content displayed before this image.
What I basicly want to achieve:
<p>First Paragraph of the_content</p>
<img>The Post's Featured Image</img>
<p>The rest of the_content</p>
I someone is able to help me.
Thanks in advance!
You can do this using the ‘the_content’ filter:
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;
}
Of course, you can add options to the the_post_thumbnail() function to define which size of thumbnail you’d like to use, etc… http://codex.wordpress.org/Function_Reference/the_post_thumbnail