 <pre><code>function mom_get_first_image() { global $post; if(preg_match_all('/&lt;img.+src=[\'"]([^\'"]+)[\'"].*&gt;/i', $post-&gt;post_content, $matches)) $first_img = $matches[1][0]; else $first_img = "images/logo.png"; return $first_img; } </code></pre>