Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So I limited the amount of characters per post via the_excerpt('50') but it removes the image that I added to my post. How can I bring that image back so it shows up above the post then limits the characters?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

The problem is that the_excerpt() strips all HTML. There's a good reason for this: what if the 49th word of a 50 word excerpt was the first word of a bulleted list? Or the second word in an <h1>?

The way I would work around this is by using post thumbnails. These allow you to have an image you can choose to display at different sizes (or not at all) depending on the situation. I've often used them as small image queues above excepts which link to a full post. I would then insert a larger version of the image inside the post.

If your theme doesn't currently support post thumbnails, you can activate them by adding:

add_theme_support('post-thumbnails');

to your functions.php. You can also add custom image sizes in functions.php like so:

add_image_size('sideFeature', 252, 999, false);

where the arguments are: name, width, height, and crop. Here's the reference. I've made the height "999" here because I only really care about the width being a certain amount. Afterward, you can then call:

the_post_thumbnail('sideFeature');

inside of your theme to display it when you're in the loop.

If you need more than one thumbnail, you can use something like the Multiple Post Thumbnail plugin. I've used it a few times, and it's worked quite well for me.

share|improve this answer
add comment

Gavin is totally right about the excerpt needing to strip html, but sometimes you really do want to keep some of that html. Then what?

I wrote an excerpter that preserves key html tags. You can find it here: Limit to a certain number of characters in excerpt, but keep html tags and only whole words

And maybe you have some suggestions to make it better?

share|improve this answer
add comment

Your Answer

 
discard

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.