Archived topic
Missing Excerpt in Blog Post
14 replies · Started by Roman on August 23, 2018
I've just installed the GP Theme "Blogg". Unfortunately, the excerpt is not displayed on the post page. Can I set this in the customiser or do I have to install it with a code snippet? If so, how does it work in the theme (GH Hooks?).
Thank you!
Cheers, Roman
Hi there,
excerpts that are added via the Post Excerpt Meta field in the post editor are not added to the Single Post by default, only in the Blog page articles. We can add it with some code.
Where would you want the excerpt to be displayed?
Hi David,
Thanks for your help. I need the Post Excerpt Meta the article image on the Single Post Page.
Cheers, Roman
Hi Roman,
where exactly on the Post page? This hook visual guide shows the places we can simply hook the excerpt:
https://docs.generatepress.com/article/hooks-visual-guide/#single-post
Let me know :)
Would be perfect after_entry_header :)
So lets use the new Elements module:
https://docs.generatepress.com/article/hooks-element-overview/
Create a new Hook and add this content:
<?php
if ( has_excerpt() ) {
$single_excerpt = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id));
echo '<div class="single-excerpt">' . $single_excerpt . '</div>';
}
?>
then these options:
Hook: after_entry_header
Execute PHP: Check
Then on Display Rules set the Location to Posts > All Posts.
Then a little bit of CSS to give it some padding:
.single-excerpt {
padding: 20px 0;
}
you can add other properties to this to style it.
Thank you, but know i get the error: Unable to execute PHP as DISALLOW_FILE_EDIT is defined.
This article explains that:
https://docs.generatepress.com/article/disallow-php-execution/
I did, but now the PHP code is played directly. So PHP execution is still locked.
Any Idea?
Thank you!
PHP execution will only be disabled if this line exists in your wp-config.php file: define( 'DISALLOW_FILE_EDIT', true );
This line is usually added by a security plugin if you didn't add it yourself.
ok, very strange.
i've deleted the define( 'DISALLOW_FILE_EDIT', true ); and then i have the checkbox "run PHP". but if i publish the code, it only shows the code. on the right place, but only the code.
Got it. It was my mistake, I had an error in the php-tag. sorry for that and thanks for your help!
No problem :)
good morning,
I used the code provided by david, 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 '
';
}
?>
thank you for your help
alex
Hi Alessio, please raise a new topic
EDIT: Found :) https://generatepress.com/forums/topic/excerpt-in-blog-post-with-the-new-elements-module/