WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] the_excerpt(); displaying full content (7 posts)

  1. cmdshiftdesign
    Member
    Posted 2 years ago #

    Instead of full article content to display on my search results page, i prefer for just an excerpt of the article to show — BUT my use of the <?php the_excerpt(); ?> tag in the search.php template keeps returning the full post content. :/ Any ideas what I am overlooking?

    [code moderated - please use the pastebin]

  2. cmdshiftdesign
    Member
    Posted 2 years ago #

    OK, I figured out my issue and it is that I misunderstood the function of the_excerpt.

    I always understood the excerpt to either be the text defined as the excerpt in wordpress OR the first 100 (or whatever) characters in the post. But, looks like I'm wrong. If no text is in the "excerpt" field of a post will the full content just display.

  3. Jeff Clark
    Member
    Posted 2 years ago #

    add this to your functions.php file

    it is a filter that will allow you to control the length of your excerpt by returning 20 that is your excerpt length. That number is then passed into your filter allowing you to manipulate the output. Now whenever you call the_excerpt() it will run you filter.

    // the code below is from the codex

    function custom_excerpt_length( $length ) {
    return 20;
    }
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

  4. Jeff Clark
    Member
    Posted 2 years ago #

    also make sure you are running the_excerpt() in the loop :)

  5. cmdshiftdesign
    Member
    Posted 2 years ago #

    Thank you! I have that in place in my functions.php file... but i just did a little test -- made a function file with ONLY that and it worked... so looks like it is being interfered with with something else in that file...

    the plot thickens...

  6. cmdshiftdesign
    Member
    Posted 2 years ago #

    VICTORY!

  7. Jeff Clark
    Member
    Posted 2 years ago #

    that is odd. Did you place that at the end of the functions.php file?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags