• 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 Custom Read More Link To Excerpts

The code in this tutorial enables you to do 2 things :

  1. You can control the length of the excerpt
  2. Add a custom read more link to the end of your excerpts
Genesis Users Note : This code assumes you’ve set the Genesis > Theme Settings > Content Archive > Display > settings to show Entry Excerpts and not Entry Content

Usage In Functions File

Add the following PHP code to the end of your child themes functions file.

This code uses get_the_excerpt filter

add_filter( 'get_the_excerpt', 'link_excerpt_more' );

function link_excerpt_more( $output ) {

$more = sprintf( ' <a href="%s" class="more-link" rel="bookmark">' . __( 'Read More' ) . '</a>', esc_url( get_permalink() ) );

return $output . $more;
}

You can also use the_excerpt filter like this :

add_filter( 'the_excerpt', 'link_excerpt_more' );

function link_excerpt_more( $output ) {

$more = sprintf( ' <a href="%s" class="more-link" rel="bookmark">' . __( 'Read More' ) . '</a>', esc_url( get_permalink() ) );

return $output . $more;
}

Customize Code

  • Swap out the 15 in the 1st code snippet to control the length of the excerpts.
  • You can also modify the Read More text in the 2nd code snippet.

Related Tutorials

  • Setting To Display Entry Excerpts on Any Archive Page Template

Read More

Reader Interactions

Comments

  1. Cindy Clearwater says

    October 21, 2019 at 8:21 am

    Hi there! I used the code to change the text to ‘ … Learn More’ which worked great … but even when it was the default ‘…’ it was not a live link. How do I make it link to the post??

    Log in to Reply
    • Brad Dalton says

      October 21, 2019 at 9:48 pm

      Hello Cindy

      Use this snippet when using excerpts NOT the content limit.

      Note : This code only works if you’ve set the Customize > Theme Settings > Content Archive > Display > settings to show Entry Excerpts and not Entry Content.

      Log in to Reply

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