Ads By Google

Better Display Of Images In your WordPress Post Excerpts

wp-logo

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 &raquo;'); ?> (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 Fancy Excerpt. 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. Justin Tadlock has the news and tips on how you can upgrade you Theme to take advantage of this feature when the big update comes.

Share This Post
Ads By Google
 

Free Updates

Subscribe to receive Free WordPress Theme Tips, Reviews and Discount Codes

Related WordPress Theme Tips

Display Thumbnail Images In Post ExcerptsMaybe for some reasons or another, you do not like to use plugins to display images in your post excerpts. Using plugins do have limitations. For one, you cannot control...

Insert Thumbnail Images In Your Homepage Post ExcerptsUnder normal circumstances, if you are not using a theme that comes with the the Customs Filed functions written in, you cannot insert images to your homepage excerpts. Many bloggers...

Add Text And Image Shadows To Your WordPress PostTo add shadows to your text in your WordPress blog, all you need is a simple line of code. It works with all major browsers except Internet Explorer, which not...

CSS Codes To Highlight WordPress Post Background Color.Highlighting certain part of your post will attract your reader’s focus on something important that you might want to relate in your post. This following piece of codes will let...

Wrapping Text Around Your Thumbnail ImagesWordPress 2.9 latest feature that lets users post thumbnail images in their post excerpts has certain limitations which makes me refrain from using this feature. This new feature however will...

Those who found this page were searching for:

  1. show image in rss excerpt
  2. wordpress excerpt does not display
  3. "wordpress 3" show image in excerpt
  4. cut wordpress excerpts in half
  5. show image wp post
  6. free single page wordpress theme
  7. thesis display rss feed in post wordpress
  8. image page display wordpress genesis
  9. show images after displaying
  10. thesis excerpts post

2 Responses to “Better Display Of Images In your WordPress Post Excerpts”

Read below or add a comment...

  1. Jamy says:

    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!!!

    • Costa says:

      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.