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.

I know this might seem like a silly question, but I've searched online and can't find what I"m looking for. It seems like I've used the following markup before (though modified) to limit the number of words that appear where this snippet is place. Can anyone help? I don't necessarily want to Read More link, just to be able to limit # of words in a few - NOT ALL - of my template files.

<?php the_content(); ?> 
share|improve this question

1 Answer 1

Limiting the content to a number of words is a little tricky. Limiting the number of characters is much easier to do and is built in to WordPress already.

You can use the the_excerpt() and get_the_excerpt() functions to limit the number of characters in the beginning of the post content. The example in the first link, shows how to change the number of characters chosen.

add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
/**
 * Change the excerpt length to 20 characters.
 */
function custom_excerpt_length() {
    return 20;
}

You can also specify an exact excerpt in a post. This allows you to create a custom excerpt that describes the post better than the first few characters.

share|improve this answer
    
Okay, do I have to use a modified <?php the_excerpt(); ?> to get this to work? –  streetfire Sep 30 '13 at 18:59
    
Whether you modify it or not is up to you. The default max characters is 55. The link I provided above gives you all these details and more. The link provided there, gives you more content and excerpt options as well. –  Charles Clarkson Sep 30 '13 at 19:20

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.