Site logo

[Resolved] Display Excerpt on post (as added in excerpt field) and read more

Home Forums Support [Resolved] Display Excerpt on post (as added in excerpt field) and read more

Home Forums Support Display Excerpt on post (as added in excerpt field) and read more

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1700106
    JC

    Hello,

    I think I have found the solution for one of my problems but just want to confirm.

    Issue 1 is when Excerpt field is filled in, custom excerpt, it does not display on category views so will this solve it?: https://docs.generatepress.com/article/activating-read-custom-excerpt/

    Issue 2, displaying the custom excerpt (as added to excerpt field during post edit) on a post and changing it to H2. What is the best way to go about this without adding any additional plugins or altering the theme files.

    I do have the paid version so can this be done via ELEMENTS if so any help/direciton would be apprediated 🙂

    #1700170
    JC

    For ISSUE 2, I have tried this:

    add_action('generate_after_entry_header', '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>';
        }  
    }

    The only issue is the image is set to display below title (Customiser/Layout/Blog) but now I get the Excerpt first then image, I want it below the image and not before.

    #1700266
    David
    Staff
    Customer Support

    Hi there,

    1. Yep thats correct.
    2. In that code try changing the first line ie.

    add_action('generate_after_entry_header', 'db_single_post_excerpt');

    to:

    add_action('generate_after_entry_header', 'db_single_post_excerpt', 50);

    #1700833
    JC

    Thank you David. Just for the sake of learning what does the 50 represent? That sets it to priority 50, right?

    #1701040
    Leo
    Staff
    Customer Support

    Yes exactly 🙂

    #1839648
    JC

    Hello,

    So I have this setup:

    add_action('generate_after_entry_header', 'db_single_post_excerpt', 50);
    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"><h2>' . $single_excerpt . '</h2></div>';
        }  
    }

    The problem is that the output is this;

    <h2><p>excerpt text</p></h2>

    I don’t want the Paragraph elements in there it must only be in the H elements. What am I doing wrong or how can I do this better maybe by setting it up via ELEMENTS?

    #1839653
    JC

    I feel so enabled… I solved it with a bit of Googling and luck so sharing.

    I changed:
    the_excerpt
    to
    get_the_excerpt

    So the output is now without the paragraph elements for the excerpt. 🙂

    /** excerpt on post and wihtout paragraph elements **/
    add_action('generate_after_entry_header', 'db_single_post_excerpt', 50);
    function db_single_post_excerpt() {
        if ( is_single() && has_excerpt() ) {
            $single_excerpt = apply_filters('get_the_excerpt', get_post_field('post_excerpt', $post_id));
            echo '<div class="single-excerpt"><h2>' . $single_excerpt . '</h2></div>';
        }  
    }
    #1839686
    David
    Staff
    Customer Support

    Glad to hear you found the solution 🙂 And thanks for sharing!!!

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