[Support request] Show post excerpt on single post

Home Forums Support [Support request] Show post excerpt on single post

Home Forums Support Show post excerpt on single post

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #635829
    Manish

    Is there any way to show post excerpts on the single post, like below the featured image and before the article begins?

    #635987
    David
    Staff
    Customer Support

    Hi there,

    are you using the Excerpt meta in the WP editor? If so where would you want these to be displayed on the single post?

    #636000
    Manish

    Yes, using the excerpt meta in wp editor.

    Ideally I would like the excerpts to appear just below the featured image on a single page.

    It helps the readers to get an excerpt or summary before the main content begins.

    #636124
    David
    Staff
    Customer Support

    OK, we could add this function:

    add_action('generate_before_entry_title', 'db_single_post_excerpt');
    function db_single_post_excerpt() {
        if ( is_single() && has_excerpt() ) {
            $single_excerpt = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id));
            echo '<div class="single-excerpt">' . $single_excerpt . '</div>';
        }   
    }

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

    You can then style it with the single-excerpt CSS Class

    #636612
    Manish

    Ok. That puts it above title.

    I need it after the featured image. Unfortunately you don’t have a hook

    generate_before_entry_content

    sorely needed.

    #636767
    David
    Staff
    Customer Support

    Ah ok, try:

    generate_after_entry_header

    You may find this useful:

    https://docs.generatepress.com/article/hooks-visual-guide/

    #636778
    Manish

    Yes, ideally it should work but for some reasons the output of this is coming where the output of generate_after_entry_title should come, i.e, before the featured image instead of after.

    Please check if the hook code is correct.

    #636784
    David
    Staff
    Customer Support

    OK, try adjusting the priority by changing the add_action like so:

    
    add_action('generate_after_entry_header', 'db_single_post_excerpt', 30);
    
    #1689306
    PJ

    I had the same problem so changed it to generate_after_entry_title which puts it under the title.

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