Archived topic
Excerpt in Blog Post with the new Elements module
3 replies · Started by Alessio on August 25, 2018
good morning,
I open a new thread because maybe my post in https://generatepress.com/forums/topic/missing-excerpt-in-blog-post/ was not seen, been that post already marked as solved.
in order to add the excerpt under the title on single post pages I used the code provided by david
<?php
if ( has_excerpt() ) {
$single_excerpt = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id));
echo '
';
}
?>
but i got an error together with the excerpt. this was the error
Notice: Undefined variable: post_id in /home/xxx/public_html/xxx/wp-content/plugins/gp-premium/elements/class-hooks.php(180) : eval()’d code on line 3
removing , $post_id from david’s code, it works, but I would like to know if now the edited code I am using is correct or not
<?php
if ( has_excerpt() ) {
$single_excerpt = apply_filters(‘the_excerpt’, get_post_field(‘post_excerpt’));
echo ‘
‘ . $single_excerpt . ‘
‘;
}
?>
thank you for your help
alex
Hi there,
Try this instead:
<?php
if ( has_excerpt() ) {
$single_excerpt = apply_filters('the_excerpt', get_post_field('post_excerpt', get_the_ID()));
echo '<div class="single-excerpt">' . $single_excerpt . '</div>';
}
?>
Let me know :)
hi tom
PERFECT :-)
thank you as usual
alex
Awesome, glad I could help! :)