• Resolved Jim

    (@kernix)


    FYI, I did just add support for add_post_type_support in case that matters, but I noticed this a couple of months ago. My theme is based on _s, here is what I have in my functions.php file:

    function tower_set_excerpt_length(){
        return 40;
    }

    Here is what is inside my content-posts template part for single.php:

    <div class="entry-content">
       <?php the_excerpt(); ?>
    </div>

    I am getting the excerpt for my blog post but it’s not getting cut off at 40 words and my excerpt is 44 words. I tried CTRL+F5 to clear my cache just in case it was that. Any idea what I need to do?

    The link is to my blog page which has one post (site is only a few days old).

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Jim

    (@kernix)

    Update: I changed the length to 10 words and forgot to change it back. And I still saw my 44 words. Since that except if the opening paragraph for my contact page (just testing), I removed the excerpt from the post. Then I refreshed the blog page and the excerpt was the 1st 10 words from my article.

    I remember this happening when I was building the theme:

    1. If the posts did NOT have an excerpt, the_excerpt would return the excerpt_length from the 1st words in the article, BUT
    2. If the post had an excerpt, it would return the entire excerpt even if it exceeded the excerpt length.

    Sound familiar to anyone?

    did you check https://developer.wordpress.org/reference/hooks/excerpt_length/#more-information
    i.e. do you have the add_filter(..) part in your functions.php?

    also, if you are using a hand-typed excerpt, it’s length will not be effected by that filter.

    PS:
    ignore this answer, seems you have solved the mystery already.

    Thread Starter Jim

    (@kernix)

    No, I didn’t solve it and yes I have add_filter – missed pasting that in. Read my reply where it filters to the word count when there is NOT an excerpt. Also, I pasted the excerpt in – I have never hand-typed in that field.

    Moderator bcworkz

    (@bcworkz)

    It doesn’t matter if you type or paste, the result is there is text in post_excerpt. The auto-trimming behavior is only used when post_excerpt is empty. A lot of people don’t like the auto-trimming because any HTML tags (anchor links for example) that might occur in the excerpted portion get stripped out.

    Personally, I prefer the <!--more--> tag approach to manually define where excerpts break. It’s not for everyone but it works for me.

    I’m not sure what’s left to solve. There are three possible approaches. Put text by any means into post_excerpt. Place a <!--more--> tag in post_content. Or leave post_excerpt empty and let WP auto-trim post_content.

    Thread Starter Jim

    (@kernix)

    I just thought about that earlier – I was thinking that it would trim my manually entered excerpt to the same word count. Thanks for confirming that.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘the_excerpt is working but not excerpt_length’ is closed to new replies.