Support » Fixing WordPress » the_excerpt(); displaying full content

  • Resolved cmdshiftdesign

    (@cmdshiftdesign)


    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]

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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.

    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 );

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

    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…

    VICTORY!

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

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘the_excerpt(); displaying full content’ is closed to new replies.