Created
March 5, 2014 14:20
-
-
Save sicksand/9368055 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Display the first image of wordpress post. | |
Put these function on file : functions.php | |
usage <?php echo _get_first_image(); ?> | |
*/ | |
function _get_first_image(){ | |
global $post, $posts; | |
$first_img = ''; | |
ob_start(); | |
ob_end_clean(); | |
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); | |
$first_img=""; | |
if(isset($matches[1][0])) | |
$first_img = $matches[1][0]; | |
return $first_img; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment