Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!!

share|improve this question
    
How would this "defined" paragraph would look like? –  Marcin Bobowski Feb 13 '13 at 23:41
    
Just as any paragraph... I don't know the content. I can 'inject' a class on the <p> tag with jQuery $('p:nth-child(5n+1) span.Noted').addClass('Note1');. Perhaps it helps. –  José Luis Quintero Feb 14 '13 at 14:08
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.