[Support request] post excerpt error in homepage

Home Forums Support post excerpt error in homepage

  • This topic has 12 replies, 4 voices, and was last updated 1 year ago by Leo.
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #984635
    James

    Hello,

    Only one post displays the whole post text on homepage. Other posts display titles without excerpts (I have set the excerpts length to zero).

    I want to display titles only. What’s the problem of the only post? Please help me.

    Thanks very much!

    #984684
    David
    Staff
    Customer Support

    Hi there,

    seen this a couple of times before – for no explainable reason WP outputs the content.
    What happens if you create a new post does that one display correctly?

    #1009457
    Olasiyan

    Please I’m facing the same problem… I think it happens when you changed the post format from standard to any other format.
    In my old theme, if I wanted to publish music I select format as music, video i select format as video…
    Going through all my published post contents… All those posts showed the whole text content.

    #1009460
    Olasiyan

    Except those ones published in standard format… Even in search or tag pages they display the whole post contents

    #1009469
    Leo
    Staff
    Customer Support

    Hi there,

    Try this PHP snippet:

    add_filter( 'generate_show_excerpt', function( $show ) {
        if ( 'audio' === get_post_format() ) {
            $show = true;
        }
    
        return $show;
    } );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    Let me know if this helps 🙂

    #1009491
    Olasiyan

    Thanks it works

    #1009506
    Leo
    Staff
    Customer Support
    #1011258
    Olasiyan

    I just detected this morning that same error occurred for videos as well… And what if i have other post format like Quote and others that I’ve used in my previous theme? How do we deal with that?

    #1011376
    David
    Staff
    Customer Support

    Hi there,

    so this part of the code checks to see if its an audio post:

    if ( ‘audio’ === get_post_format() )

    We can extend that to check for multiple post formats eg.

    if ( 'audio' === get_post_format() || 'video' === get_post_format() || 'quote' === get_post_format() )

    #1011391
    Olasiyan

    I’m getting php error after inserting this new code

    #1011394
    David
    Staff
    Customer Support

    the code should look like this:

    add_filter( 'generate_show_excerpt', function( $show ) {
        if ( 'audio' === get_post_format() || 'video' === get_post_format() || 'quote' === get_post_format() ) {
            $show = true;
        }
    
        return $show;
    } );
    #1011822
    Olasiyan

    It did work for now… If I notice any error in any other format… Will get back to you

    #1011858
    Leo
    Staff
    Customer Support

    You can keep adding the condition in the if statement if you need other post format included as well.

    You can see all of them listed here:
    https://codex.wordpress.org/Function_Reference/get_post_format

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