Title: Get First Embed or Object
Last modified: August 19, 2016

---

# Get First Embed or Object

 *  Resolved [freshifreshy](https://wordpress.org/support/users/freshifreshy/)
 * (@freshifreshy)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/get-first-embed-or-object/)
 * Does anyone know a way that I could check a post for an embedded video and then
   do something with that video?
 * I want to create a video thumbnail (or a small version of the video) for posts
   that contain embedded videos, but I’m having a hard time figuring out how I might
   do this…

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/get-first-embed-or-object/#post-1476771)
 * See [this Codex page](http://codex.wordpress.org/Function_Reference/get_posts#Show_all_attachments).
 *  Thread Starter [freshifreshy](https://wordpress.org/support/users/freshifreshy/)
 * (@freshifreshy)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/get-first-embed-or-object/#post-1476897)
 * If it’s embedded, it’s not going to show up as an attachment… Not sure how I 
   could use this…
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/get-first-embed-or-object/#post-1476979)
 * Sorry – I was thinking of a video file that you’d uploaded. I don’t think there’s
   an easy way to achieve what you’re after. Essentially, you would need to search
   the whole post content for a specific shortcode or url.
 *  Thread Starter [freshifreshy](https://wordpress.org/support/users/freshifreshy/)
 * (@freshifreshy)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/get-first-embed-or-object/#post-1477078)
 * I ended up writing a PHP function. It looks like this.
 *     ```
       function show_thumb() {
   
       	global $post, $posts;
   
       	$thumb = '';
   
         	ob_start();
         	ob_end_clean();
   
       	$output = preg_match_all('/(\<object.*\<\/object\>)/is', $post->post_content, $matches);
       	$thumb = $matches [1] [0];
   
       	if(empty($thumb)) {
   
       		$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
         		$thumb = $matches [1] [0];	
   
       		if(empty($thumb)) {
   
       			$thumb = "/images/default.jpg";
   
       		} else {
   
       			return '<img src="'.$thumb.'" alt="thumb-'.$post->ID.'" />';
   
       		}
   
       	} else {
   
       		return $thumb;
   
         	}
   
       }
       ```
   
 *  [Tara Rotten](https://wordpress.org/support/users/tara-rotten/)
 * (@tara-rotten)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get-first-embed-or-object/#post-1477210)
 * Hey,
 * Your code is great, cant get it to pull in the object’s ie videos though.
 * Ive wrapped all videos in a div (<div class=video>) is there a way to search 
   for this div instead. (all videos are embeded from youtube)

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Get First Embed or Object’ is closed to new replies.

## Tags

 * [embed](https://wordpress.org/support/topic-tag/embed/)
 * [object](https://wordpress.org/support/topic-tag/object/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [Tara Rotten](https://wordpress.org/support/users/tara-rotten/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/get-first-embed-or-object/#post-1477210)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
