[Resolved] Search Results page – How to display custom excerpts using the tag

Home Forums Support [Resolved] Search Results page – How to display custom excerpts using the tag

Home Forums Support Search Results page – How to display custom excerpts using the tag

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2379091
    VR

    Hello,

    Per GP Support’s request, I am following up on posts in this thread (Post ID #2379026):

    https://generatepress.com/forums/topic/automatic-excerpts-and-the-manual-read-more-tags-looping-in-harmony/

    I’ve placed the Search Results page URL in the private info box on this post.

    Thanks!

    #2482702
    VR

    Hello,

    I am moving the questions from another thread (still unanswered) here so everything is in one place:

    –> Prior thread URL: https://generatepress.com/forums/topic/automatic-excerpts-and-the-manual-read-more-tags-looping-in-harmony/#post-2378101

    Two more questions:
    
    1) Is there a way to adapt the code above (post #2337324) to also work for the default Search Results post excerpts? They don’t use the “GB Headline block” so the code doesn’t work for them.
    
    Know we can create a whole new Search Results template, per https://generatepress.com/forums/topic/design-search-page/, but since the only change we need is displaying dynamic excerpts when the <!–more–> link exists in the post content, would rather not have to create a whole new template to achieve that.
    
    2) For static WP Pages – Is it possible to add a snippet to also include an auto-generated excerpt on the Search Results page? Or, will the client need to add a manual custom excerpt if they want text to appear for Pages, too?
    
    Thanks!

    Still looking for help with the above two items. Here’s a sample Search Results page showing the <!–read more–> link text is NOT rich-text on the Results page: https://jillk5.sg-host.com/?s=meeting

    I’ve placed admin credentials for the site in the Private Info box.

    Thank you!

    #2482912
    Fernando
    Customer Support

    Hi VR,

    Let’s try to address #1 first.

    Can you try adding this PHP snippet?:

    add_filter( 'generate_show_excerpt', function( $show ) {
    	global $post;
        if ( strpos( $post->post_content, '<!--more-->' ) && is_search() ) {
            return false;
        }
        return $show;
    } );

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

    #2483943
    VR

    Terrific. thank you! That takes care of Item #1.

    For Item 2 – as seen in the Search Results page here: https://jillk5.sg-host.com/?s=meeting
    … the “About” and “Home” pages do not auto-generate a summary using the existing body text on the page. Any help you can provide to automate this (when no manual excerpt exists) rather than having the Client have to manually create excerpts for all pages would be much appreciated.

    #2484049
    Fernando
    Customer Support

    This is WordPress core already. Can you try adding this Snippet first?:

    add_post_type_support( 'page', 'excerpt' );

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

    #2485117
    VR

    Thanks. We added the snippet and can now see the Excerpt option in the right sidebar of Pages. It doesn’t seem to be auto-creating an excerpt, though, if none exists in the Search Results page, tho (see “About” page):

    https://jillk5.sg-host.com/?s=meeting

    Interestingly, the “Home” page does appear to display the Headlines from the current Home page (“NEXT MEETING LATEST NEWS”), but nothing else.

    Question: Will the client have to enter manual excerpts for all pages they want content to appear in Search Results and other Index type pages?

    Thanks for your help!

    #2485294
    Fernando
    Customer Support

    If your text is not in a Grid or nested under multiple Blocks, the excerpt for pages should be automated. Otherwise, you’ll need to add a manual excerpt.

    It’s a core WordPress issue. The excerpt function doesn’t parse nested blocks’ content. You will have the same issue if you use a core Group Block.

    As mentioned, the workaround is to use a Manual Excerpt in your posts. So to answer your question, for pages like your About Page, with how it’s structured, yes, your client needs to add a manual excerpt.

    #2486983
    VR

    Okay, gotcha. Thanks for the clear explanation. We’ll move ahead with manual excerpts and hope that WordPress core resolves the issue in a future update.

    Thank you!

    #2488279
    Fernando
    Customer Support

    You’re welcome, VR!

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