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


Comments

2 responses to “Add Custom Read More Link To Excerpts”

  1. Cindy Clearwater Avatar
    Cindy Clearwater

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

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

Leave a Reply

Join 5000+ Followers

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