Archived topic
Show post excerpt on single post
8 replies · Started by Manish on July 30, 2018
Is there any way to show post excerpts on the single post, like below the featured image and before the article begins?
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?
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.
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
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.
Ah ok, try:
generate_after_entry_header
You may find this useful:
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.
OK, try adjusting the priority by changing the add_action like so:
add_action('generate_after_entry_header', 'db_single_post_excerpt', 30);
I had the same problem so changed it to generate_after_entry_title which puts it under the title.