WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to include an image within the auto excerpt?

So in the editor you have image then some text and once live it includes the image and not just the text?

share|improve this question
up vote 3 down vote accepted

Yes, you can do that, but you'll need to tweak the <?php the_excerpt(); ?> function. This is a good article on how to do that:


To sum up the article in case it goes away, put this in your theme's functions.php file:

function improved_trim_excerpt($text) {
        global $post;
        if ( '' == $text ) {
                $text = get_the_content('');
                $text = apply_filters('the_content', $text);
                $text = str_replace('\]\]\>', ']]&gt;', $text);
                $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
                $text = strip_tags($text, '<img>');
                $excerpt_length = 80;
                $words = explode(' ', $text, $excerpt_length + 1);
                if (count($words)> $excerpt_length) {
                        array_push($words, '[...]');
                        $text = implode(' ', $words);
        return $text;
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'improved_trim_excerpt');

Note this line, this is where you're telling the function to strip all tags except <img> tags. You could add others if you'd like to include paragraph tags or whatever:

$text = strip_tags($text, '<img>');

Then call the_excerpt(); as usual in your theme files (index.php, single.php etc).

Best of luck!

share|improve this answer
Thank you, i'll give it a go :) – Jezthomp Mar 14 '12 at 20:42

A bit improvement .if you want to remove [..] with Read more and with a css class and Font awesome icon replace

array_push($words, '[...]');


array_push($words, '<a class="read-more" href="'. get_permalink( get_the_ID() ) . '">Read More<span><i class="icon-arrow-right"></i><span></a>');


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.