Wednesday, May 02, 2012

Get the first image from your wordpress post....if you need :)

Code here:

global $post;
$firstIMG = ”;
$resultSET = preg_match_all(‘/<img.+src=[\'"]([^\'"]+)[\'"].*>/i’, $post->post_content, $allIMAGES);
$firstIMG  = $allIMAGES[1] [0];
if(empty($firstIMG  ))
{
$firstIMG  = “path to custom image”;
}    else    {
echo $firstIMG;
}

No comments: