Posted By

lgarcia on 09/30/10


Tagged

wordpress


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

lgarcia
acousins


Extract first image from a post (Wordpress)


 / Published in: PHP
 

  1. function get_image_src($posti = null) {
  2. if (!$posti)
  3. global $post;
  4. else
  5. $post->post_content = $posti;
  6.  
  7. $the_content = $post->post_content;
  8. $pattern = '!<img.*?src="(.*?)"!';
  9. preg_match_all($pattern, $the_content, $matches);
  10. $image_src = $matches['1'][0];
  11. return $image_src;
  12. }

Report this snippet  

You need to login to post a comment.