Allow the_excerpt() to accept arguments like the_content()

  1. David Cavins


    I've been using excerpts quite a bit on a new project which is more CMS-y, and they've not been as easy to use as I'd like. I'd like for the_excerpt() to accept parameters, parallel to how the_content() works.

    As an alternative to adding a "read more" tag via functions, one could specify the_excerpt('Read more...'). Instead of hooking to the excerpt_length action, one could specify the length directly, like the_excerpt('Read more...', 40).

    These two arguments would have come in handy for me, as I'm using a variety of lengths and styles of excerpts (sometimes on the same page, like a magazine-style front page).

    Thanks for listening,


    Posted: 5 years ago #
  2. Ziv


    These two parameters for the_excerpt() function would be great!

    Posted: 5 years ago #
  3. MHR Writer

    Hi dcavins,

    I have learned an interesting thing from your post.

    I am curious to know that
    1) either this the_excerpt() works in php files individually created for another site?
    2) could you give an example that how the_excerpt() simply apply in the coding of php file.

    Eagerly awaiting the reply.

    Posted: 5 years ago #
  4. David Cavins


    A good example of the using the_excerpt() is in the content.php file within the theme twenty twelve:

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    		<div class="entry-summary">
    			<?php the_excerpt(); ?>
    		</div><!-- .entry-summary -->

    Read the section the_excerpt vs the_content here for an understanding of why you might like to use the excerpt from time to time:

    Posted: 5 years ago #
  5. alajoann

    On several occasions, I have copied/pasted a .php code snippet that limits the number of words in an excerpt. (Although limiting the number of characters would be better.) I think a lot of people would appreciate being able to do this more simply.

    Another related point:

    I have not figured out how to remove content headings from the excerpt. (Though the HTML markup is removed!)

    I try to write like a journalist - with something meaningful in the first sentence that is quick and easy to absorb. Because I use a heading at the top of the content, I always need to manually create an excerpt - or else the heading is included in the excerpt!

    Posted: 5 years ago #
  6. ConcertPass

    Hello dcavins,
    one year has passed since your suggestion and it is still a great idea; the two parameters for the_excerpt() would add flexibility to the function.

    Posted: 4 years ago #
  7. le mie nozze


    Also I think it's a great idea!
    I call users who have not yet put the 5 stars to do it (ConcertPass, alajoann and others).

    Posted: 3 years ago #
  8. carbrandsinfo

    I am using the_excerpt() for display the category description. I really like this function.

    Posted: 3 years ago #
  9. dogpetinfo

    the_excerpt() is one of the great function to display description but I think it should default enable to display category description.

    Posted: 3 years ago #
  10. logopearl

    Please tell me can i use it in PHP?

    Posted: 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.

  • Rating

    28 Votes
  • Status

    This idea is under consideration