Archived topic
Can we add excerpts above posts using hooks?
5 replies · Started by jhmattern on January 8, 2020
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!
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
Thanks so much! I should be doing this site's changeover next week, so I'll give this a try.
You're welcome
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!
Awesome - glad to hear that!