< BACK TO POST
LinkedIn Facebook Twitter

Blog

To Get First Image From Post (WP)

February 19th, 2010 | Php , Wordpress

I want to share the code I used for my blog. I needed to get the first attachment from each post and show at frontpage, so the solution is below. You have to put this in the loop.
$content = get_the_content();
preg_match_all('/<img[^>]+>/i',$content, $result);
$thumb = $result[0][0];

Leave a Reply