Skip to content

Instantly share code, notes, and snippets.

@derpixler
Created June 7, 2011 14:57
Show Gist options
  • Save derpixler/1012412 to your computer and use it in GitHub Desktop.
Save derpixler/1012412 to your computer and use it in GitHub Desktop.
Custom Excerpt with Image and some other stuff from a Post.
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');
@derpixler
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment