Archived topic
Display latest post in header
13 replies · Started by Björn on April 19, 2022
Hi. I let the latest post display on top of my page just like it was described here:
https://generatepress.com/forums/topic/display-latest-post-in-header/
BUT: the "Read more" link links to the front page. The headline links correctly to the full post.
In The code it says : "$return .= '
';"
I can't find any possibility to change that.
Hi there,
which code did you use ? Theres quite a few options in that topic.
Oh, yeah, my bad. Sorry for that.
This ist the code I am using:
add_shortcode( 'most_recent_hero_post', function() {
$latest_posts = get_posts( 'numberposts=1' );
$latest_id = $latest_posts[0]->ID;
$return = '<div style="padding: 20px 30px;"><h3 style="font-size: 20px;">Neuester Beitrag:<b><a href="' . get_permalink( $latest_id ) . '">' . get_the_title( $latest_id ) . '</a></b></h3>';
$return .= '<div class="latest-excerpt">' . get_the_excerpt( $latest_id ) . '</div>';
return $return;
} );
While there is the "Read more" at the end of the excerpt it only leads to my front page and not to the specific post. The headline indeed links to the post.
Hmmm... can't see anything wrong there and i tested a few methods on my local site and it works correctly.
Can you share a link to your site where i can see the issue?
Hmmm... does it work if you temporarily change the hook to before_main_content ? Or if you add the shortcode to the poge content ?
No, it doesn't.
Neither nor
Do you have any other functions that change the excerpt, readmore or post behaviour ?
No.
But when I check "Read more as button" in the Customizer the link changes to: "....../#more-872" and the link doesn't work at all.
Hmm... odd one. What if we got rid of the Read More ?
Getting rid of the Read more from the excerpt and adding it with a line of code?
I only know how to do the latter. And when I did that the second Read more worked.
Hi Bjorn,
What about trying to add a custom excerpt and then adding the snippet here?: https://docs.generatepress.com/article/activating-read-custom-excerpt/
Alternatively, you can also just hide it through CSS since you’ve added it in a new line. For instance, you can try adding this CSS in Appearance > Customize > Additional CSS:
.latest-excerpt .read-more {
display: none;
}
Kindly let us know. :)
Best support of the best theme!!!!
Thank you!
You’re welcome Björn! Glad to be of assistance! Feel free to reach out anytime you’ll need assistance with anything else. :)