[Resolved] Can we add excerpts above posts using hooks?

Home Forums Support Can we add excerpts above posts using hooks?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1125540
    jhmattern

    I’m getting ready to move another of my sites from Divi to GeneratePress, and I’m looking to preserve some formatting.

    You can see an example of a current post at https://nakedpr.com/pitching-bloggers/.

    Below the title, you’ll see a bold font summary of what’s to come in the post. In Divi, I just use a separate text box for this as every post was built in the Divi builder. But I’m hoping to simplify this a bit on the move by also making that summary the post excerpt, and then just pulling the excerpt in above the post content but below the title. I know a plugin I can use to do this, but I was curious if it’s possible with GP’s hooks instead of adding extra bloat to the site just for this.

    If it’s possible, what might that call look like in the hook system?

    Thanks!

    #1125793
    David
    Staff
    Customer Support

    Hi there,

    for sure – try Hooking in this PHP snippet to display the Custom Excerpt if it exists:

    <?php
    if ( has_excerpt() ) : // Only show custom excerpts not autoexcerpts ?>
    	<p class="entry-excerpt"><?php echo get_the_excerpt(); ?></p>
    <?php endif; ?>

    Either the after_entry_title or after_entry_header hook should do the trick.
    Make sure to check execute PHP

    Then you can style it using the entry-excerpt class

    #1125830
    jhmattern

    Thanks so much! I should be doing this site’s changeover next week, so I’ll give this a try.

    #1125839
    David
    Staff
    Customer Support
    #1143362
    jhmattern

    I finally got around to testing this, and I just wanted to say in case anyone else is looking to do similar, this worked perfectly.

    Thank you!

    #1143490
    David
    Staff
    Customer Support

    Awesome – glad to hear that!

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