[Resolved] priority of excerpt vs more tag

Home Forums Support [Resolved] priority of excerpt vs more tag

Home Forums Support priority of excerpt vs more tag

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #571381
    Piotr

    Hey,

    I have been using GP for about a week now and am very happy with it in general.

    However, there is one thing that bothers me which is the priority of excerpts.

    So: I start with setting the [Layout] => [Blog] => [Content] => [Archives] => [Content type] option to “Excerpt” (I want to see excerpts of posts on the home page).

    Then:
    * If there is no <—more–> tag in a post but the [Excerpt] field is filled in, everything works as expected i.e. the excerpt is being loaded from the [Excerpt] field and displayed in the archive.
    * If there is no excerpt at all anywhere (i.e. [Excerpt] field is blank and also no <–more–> tag) then everything works fine as well i.e. GP automatically extracts a pre-defined number of words from the post and displays it as the excerpt. Grand.

    However (this is where I see an issue):
    * If a post has the <–more–> tag in it, the blog archive page ignores the Excerpt field.

    To my understanding, this should work the other way around. All other themes I used (both free and paid) have this done correctly i.e. they prioritize the [Excerpt] field over the <–more–> tag content. The understanding here is that if the author of the entry made that extra effort to fill-in the [Excerpt] field, it is important and should not be ignored.

    Is there anything I can do to get this working in GP?

    #571541
    David
    Staff
    Customer Support

    Hi Piotr,

    This is one for Tom, ill get him to advise.

    David

    #571587
    Tom
    Lead Developer
    Lead Developer

    If the tag is used, we need to use the_content() function to output the content, and cut it off at the tag. That’s what allows it to use HTML.

    For the excerpt metabox to work, we need to use the_excerpt() function to output the content.

    Changing this directly in the theme would likely make some people pretty angry, as it’s been working this way for years.

    However, we can adjust it to do what we need with a filter:

    add_filter( 'generate_show_excerpt', 'tu_force_excerpt_field' );
    function tu_force_excerpt_field( $excerpt ) {
        if ( has_excerpt() ) {
            return true;
        }
    
        return $excerpt;
    }

    Let me know if that works or not πŸ™‚

    #571634
    Piotr

    Yes, it works straight away, kudos for prompt reply!

    Now, two bits of advice:

    1.

    “Changing this directly in the theme would likely make some people pretty angry, as it’s been working this way for years.”

    Buddhists change their sacred books after 3000 years if they discover that the books are incorrect. If things can be fixed, they should be fixed.

    2.

    If you don’t want to make your users jumping up and down (which I fully understand) just add an option in theme UI for controlling the priority of the <more> tag and the excerpt. This will make more users happy while keeping the other users equally happy πŸ˜‰

    Thanks again for sorting the issue!

    #571988
    Tom
    Lead Developer
    Lead Developer

    No problem! I’ll definitely keep this in mind πŸ™‚

    #579540
    Matthias Heil

    This is exactly what I’m looking for. Where exactly do I paste the code? Probably in one of the hooks fields?

    #579582
    Leo
    Staff
    Customer Support

    One of these methods: https://docs.generatepress.com/article/adding-php/

    Code snippet is the easiest if you aren’t using a child theme.

    #579679
    Matthias Heil

    Thanks ever so much, works like a charm!-)

    Edit: Is there a way of adding a “read more” tag in manual abstracts/extracts? – See https://matthiasheil.de/category/religion/ for an archive with posts that both have and have no such button…

    #579748
    Leo
    Staff
    Customer Support
    #579863
    Matthias Heil

    Cheers! Excellent!! Have a great Whitsun!!!-)

    #580161
    Leo
    Staff
    Customer Support

    No problem!

    #580183
    Piotr

    Just to add my five cents, while the method of adding the “Read more” button to posts with manual excerpts works correctly, it does not take translations into account i.e. if you switch your WordPress UI to another language, you also need to remember to update that “tu_excerpt_metabox_more” function as well.

    Not a big deal, just something to be aware of.

    #580223
    Leo
    Staff
    Customer Support

    Thanks for the inputs πŸ™‚

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.