Not sure if im going about this in the right way but, overall, ive been told to create, kind of like a news box on my home page and so, the "latest news" is going to be this clients posts.

now i know i can control the_excerpts(); content length etc but, i cant seem to find any way for it to also allow an image.

when i showed the client the "news box" he wants whatever image is associated with the post, to come through.

so i thought of "the_content();" but i dont think thats what i need(though im not sure which one will work best with what i need)

so the main questions here for me are

  1. Can i somhow get the image to come through with the excerpt, or
  2. If the excerpt function doesnt allow it, then what can i use?

3 Answers 3


Ensure that your Theme supports Post Thumbnails, and that the client sets a "Featured Image" for each post. Then, combine the_excerpt() with the_post_thumbnail(), e.g. like so:

if ( have_posts() ) : while ( have_posts() ) : the_post();

    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

        <div class="featured-image"><?php the_post_thumbnail(); ?></div>
        <div class="post-excerpt"><?php the_excerpt(); ?></div>


endwhile; endif;

Then, just use CSS to style according to your needs.


Have you tried using get_the_post_thumbnail()? You can read more about it on the Codex here. It pulls a thumbnail of the post's featured image.


Place this in your functions.php file:

remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'preserve_excerpt_format');
function preserve_excerpt_format($text)
    global $post;
    $raw_excerpt = $text;
    if ('' == $text )
        $text = get_the_content('');
        $text = strip_shortcodes($text);
        $text = apply_filters('the_content', $text);
        $text = str_replace(']]>', ']]&gt;', $text);

        $exceptions = '<p>,<a>,<em>,<strong>,<br><img>'; //PRESERVE THESE TAGS, ADD/REMOVE AS NEEDED
        $text = strip_tags($text, $exceptions);

        $excerpt_length = apply_filters('excerpt_length', $maxCount);

        $moreText = '.... <a class="blue" href="'.get_permalink($post->ID).'">Read More &gt;&gt;</a>'; //CUSTOM MORE TEXT, CHANGE AS NEEDED
        $excerpt_more = apply_filters('excerpt_more', $moreText);

        $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length+1, PREG_SPLIT_NO_EMPTY);
        if(count($words) > $excerpt_length)
            $text = implode(' ', $words);
            $text = $text.$excerpt_more;
            $text = implode(' ', $words);
    return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);

This should preserve any images that occur within the content's HTML before the Word Limit is reached.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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