I want to display the feature image inside a post text, perhaps after the third or fourth paragraph (or any) into the_content.
Searching the site I've found this code, by Amit:
add_filter('the_content', function($content)
{
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
$img = '<img src="'.$url.'" alt="" title=""/>';
$content = preg_replace('#(<p>.*?</p>)#','$1'.$img, $content, 1);
return $content;
});
Works like a charm, but I can't figure out how include the post_thumbnail after a defined paragraph (not only the second). Can anybody point me on the right direction?
Thanks in advance!!
$('p:nth-child(5n+1) span.Noted').addClass('Note1');
. Perhaps it helps.