This tutorial provides the PHP code which enables you to insert a hand crafted or manual excerpt between your single post titles (entry title) and the post info ( entry meta – entry header ).
Here’s what i’m referring to:
- Entry title or single post title
- Excerpt
- Post info or entry meta in entry header
- Entry content
You can use this code in your functions file or single.php file:
add_action( 'genesis_entry_header', 'wpsites_excerpt', 11 );
function wpsites_excerpt() {
if ( is_singular( 'post' ) && has_excerpt() ) {
the_excerpt();
}
}
Wrap The Excerpt in Heading Tags
This code wraps the excerpt in h2 tags:
add_action( 'genesis_entry_header', 'wpsites_excerpt', 11 );
function wpsites_excerpt() {
if ( is_singular( 'post' ) && has_excerpt() ) {
printf( '<h2>%s</h2>', get_the_excerpt() );
}
}
The solution in this post answers this question:
I’d like to include an excerpt in between the post title and the meta, but it seems like the hook that allows this has been deprecated.
Hey there! Had a quick question about the placement of this code –
To clean up my fucntions.php, I was hoping to move all post-related items to single.php. So I’m attempting to use this code within single.php, but my Query Monitor plugin is flagging two php notices:
“Undefined variable: id” for if ( is_singular( ‘post’ ) && has_excerpt( $id ) ) {
“Undefined variable: id” for $post = get_post( $id );
Should I be concerned about these? Or is it because I have this code on single.php and not functions.php? When I tried to move it back to functions.php, the excerpt no longer showed on posts.
Try this:
Thanks for the response! The code is working, though I’d like to wrap the excerpt in tags and quotations (” “). Right now it looks like the excerpt is being wrapped in tags, causing the quotations to appear on lines above and below the excerpt. Is there any way around that?
Sorry, my fault, I used code in the above comment and it’s not showing. I meant to say I want to wrap the excerpt in H2 tags and currently the code is automatically wrapping the excerpt in P tags, causing the extra lines for the quotation marks.
Updated the post with more code.