Title: Prevent duplicate using catch_that_image()
Last modified: August 21, 2016

---

# Prevent duplicate using catch_that_image()

 *  Resolved [ndreaas](https://wordpress.org/support/users/ndreaas/)
 * (@ndreaas)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/prevent-duplicate-using-catch_that_image/)
 * Hi guys, I’m now trying to make my own layout, but now I have a little problem.
 * I wanted to show the first image in a single post before the post title. This
   was possible putting this in functions.php
 *     ```
       function catch_that_image() {
         global $post, $posts;
         $first_img = '';
         ob_start();
         ob_end_clean();
         $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
         $first_img = $matches [1] [0];
   
         if(empty($first_img)){ //Defines a default image
           $first_img = "/images/default.jpg";
         }
         return $first_img;
       }
       ```
   
 * and this in the loop that writes the post in content-single.php
 * `<img src="<?php echo catch_that_image() ?>" />`
 * This duplicates the image and presents it before the post title, but then also
   later in the post where it’s posted.
 * I was wondering if there’s a way to remove the image from the text in the post,
   and only display it above the post title?
 * Or is there an easier way to do this?
 * (I’m working from localhost on my mac, so I can’t share a link for you to see,
   unfortunately)
 * _[please do not [bump ](http://codex.wordpress.org/Forum_Welcome#No_Bumping)–
   if it is that urgent, hire somebody – [http://jobs.wordpress.net/](http://jobs.wordpress.net/)]_

The topic ‘Prevent duplicate using catch_that_image()’ is closed to new replies.

## Tags

 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [image](https://wordpress.org/support/topic-tag/image/)
 * [single post](https://wordpress.org/support/topic-tag/single-post/)

 * 0 replies
 * 1 participant
 * Last reply from: [ndreaas](https://wordpress.org/support/users/ndreaas/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/prevent-duplicate-using-catch_that_image/)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
