WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to know if it's possible to get all the images that are in a post and his comments, make them a thumbnail and put it before (or in a sidebar or something) the post title to show, just like Twitter does. Of course it would be wonderful if you navigate to the comment where it was inserted if you click on a thumbnail, but that's something for later.

Is this possible, if so, how?

PS: I am not using a plugin, I just want to know if it can search for all the <img> tags and make them thumbnails out of no where...

share|improve this question

Getting all the images from the post, and adding them to the top of the post is relatively easy. You can do something like this: (Note, this is just a code example. I'm not 100% what you are looking for. Hopefully this is enough to get you started.)

function getImagesInThisPost() {
    global $post, $posts;
    //find all the <img>'s in the post
    $output = preg_match_all(
        $post->post_content, //from the post content

    //loop throuhg all the images we found, and put them on the page
    foreach($matches[1] as $single){
        echo "<img src=\"{$single}\">";
share|improve this answer
Thanks David, appreciated, but what about the images in comments? Can you get them too? That was the question actually =)) – Johan Jul 26 '13 at 17:03
Besides, it doesn't work. I have images, but it does not put them on top of the title. Actually, it does nothing... – Johan Jul 26 '13 at 20:30
As I said, my example is merrily a starting point. It is not a completed solution. You're calling <?php getImagesInThisPost(); ?> in you're single.php or sidebar, correct? – David Kryzaniak Jul 26 '13 at 21:48
Yes, I tried it in single.php, but nothing happened. – Johan Jul 26 '13 at 21:50

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.