Better Display Of Images In your WordPress Post Excerpts

Many WordPress users have problems displaying images in their WordPress blog if they decide to use post excerpts instead of full post in their home page. There are also many solutions and plugins available to solve this problem. In my previous post where I discussed inserting images in your post excerpts using the custom field, users can upload different images for their homepage and their singles post, however this involves some extra work which a busy lazy fellow like me can do without. Thus I looked for some short cut where I can have the exact looking image displayed in my homepage post excerpts.
The codes I found involves overwriting the default WordPress codes that specifies how post excerpts works. Can’t remember where I found them though, but I am real happy with the results. I have deleted the line of code that makes WordPress strip off all html formatting as I want all the formats and image intact. If you want to try it out, here are the codes to paste in your functions php.
Do be reminded to keep a backup of your original functions php file as this can be somewhat sensitive. One missing tag and your whole blog will not load and you won’t be able to access your dashboard to correct things. If this happens, do not panic. Just use your FTP client to delete the functions php on your server, then replace it with your original copy. Remember you must delete the corrupted functions php file, overwriting it will not do any good. So if you are adventurous and have no fear of threading into the unknown, here are the codes. Will be a piece of cake for those with experience though.
function my_wp_trim_excerpt($text) { // Fakes an excerpt if needed
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = 80;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, ' ... <a href="'. get_permalink() . '"><div class="read-more">CONTINUE READING</div></a>');
$text = implode(' ', $words);
}
}
return $text;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'my_wp_trim_excerpt');
?>
Copy and Paste the whole bunch onto your functions php file. Remember to check if you have the closing php (?>) tag at the end. Almost everytime I screw up is because I forgot to close the php codes.
After you have updated, if you haven’t done so previously, go to your Index php and look for this line.
<?php the_content('Read the rest of this entry »'); ?> (Some themes will not, or have a different sentence than this ‘Read the rest of the entry’ )
Replace that line with this:
<?php the_excerpt ?>
Now you have post excerpts that shows everything as it is, including your image. links or whatever html tags that you have used in the first 80 words. This again proves to be a not very professional way as it cuts off words midway as soon is the specified number is up. Tried to hunt for ways to overcome this with codes, but was unsuccessful so I used a plugin called . This plugin will finish the whole sentence instead of cutting off the post midway.
Seems to be a lot of work doesn’t it? Actually it will not take you more than 10 minutes. If however even 10 minutes is too much for you, then spend some money to buy a Theme that just that. The Thesis Theme has a fantastic option that simplifies everything. Not willing to do that? Then wait for WordPress 2.9 which is just round the corner. It has a kickass post image feature that will make life simple for everyone. has the news and tips on how you can upgrade you Theme to take advantage of this feature when the big update comes.
Other Awesome Articles
- Display Thumbnail Images In Post Excerpts
- Insert Thumbnail Images In Your Homepage Post Excerpts
- Wrapping Text Around Your Thumbnail Images
- Basic Magazine WordPress Theme
- Align Image In Post WordPress 2.7
- How To Create A Beautiful Background For Your WordPress Post
- CSS Codes To Highlight WordPress Post Background Color.
- Add Text And Image Shadows To Your WordPress Post
Users who found this page were searching for:
- wordpress rss feed display post images
- feature image within excerpt text wordpress
4 Responses to “Better Display Of Images In your WordPress Post Excerpts”
Comments
Read below or add a comment...
Trackbacks
-
WordPress 2.9 | Excerpts Image | WordPress Theme Customizations: The Thesis Theme has a fantastic option that s..
-
Better Display Of Images In your WordPress Post Excerpts #RTW

If you enjoyed this post, whether it's awesome or lame, consider leaving a comment or 









Yes it seems that WordPress v2.9 is about to be released. Hope it could be in a week or so as I have to start another project.
I need to use thumbnails and I would prefer not to use any plugins or other temp solution.
But what about all these 2.8 themes using plugins like “Get the image” ? Don’t they need to be re-written for 2.9 in order to work straight away with auto thumbnails generation in 2.9 ?
Can someone tell me more about that?
THANKS!!!
Hey Jamy,
I’m sure the developers of those plugins have already started checking for compatibility issues and updates should be out in time to avoid any major conflicts, if there is any. However it will be wise to deactivate all plugins first before upgrading. After you have upgraded, activate them one by one so you will know which is giving you problems.
Anyway, with the new feature in WP 2.9, I don’t think you will need plugins to display images in your homepage excerpts anymore.