Add Post Excerpt After Entry Title & Before Entry Meta in Genesis

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 ).

manual excerpt

Here’s what i’m referring to:

excerpt before post info

  1. Entry title or single post title
  2. Excerpt
  3. Post info or entry meta in entry header
  4. 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.

WordPress core source file


Comments

5 responses to “Add Post Excerpt After Entry Title & Before Entry Meta in Genesis”

  1. 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.

    1. Brad Dalton Avatar
      Brad Dalton

      Try this:

      1. 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?

        1. 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.

          1. Brad Dalton Avatar
            Brad Dalton

            Updated the post with more code.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.