• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

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

Reader Interactions

Comments

  1. homemadehooplah says

    June 23, 2016 at 12:38 pm

    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.

    Log in to Reply
    • Brad Dalton says

      June 23, 2016 at 4:45 pm

      Try this:

      Log in to Reply
      • homemadehooplah says

        June 24, 2016 at 8:56 am

        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?

        Log in to Reply
        • homemadehooplah says

          June 24, 2016 at 8:59 am

          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.

          Log in to Reply
          • Brad Dalton says

            June 24, 2016 at 9:26 am

            Updated the post with more code.

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags
 

Loading Comments...
 

You must be logged in to post a comment.