Created
June 7, 2011 14:57
-
-
Save derpixler/1012412 to your computer and use it in GitHub Desktop.
Custom Excerpt with Image and some other stuff from a Post.
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
function custom_excerpt($excerpt){ | |
preg_match_all('/<img.*?src="(.+?)"(.*?)>/i',get_the_content(),$match); | |
$image = $match[0][0]; | |
$link = '<h2><a href="'.get_permalink().'" title="'.get_the_title().'"></a></h2>'; | |
$excerpt = '<p>'.$excerpt.'</p>'; | |
return $image . $link . $excerpt; | |
} | |
function get_custom_excerpt($excerpt){ | |
preg_match_all('/<img.*?src="(.+?)"(.*?)>/i',get_the_content(),$match); | |
$array = array( | |
'image' => $match[0][0], | |
'excerpt' => $excerpt | |
); | |
return $array; | |
} | |
add_filter( "the_excerpt", 'custom_excerpt'); | |
add_filter( "get_the_excerpt", 'get_custom_excerpt'); |
Author
derpixler
commented
Jun 7, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment