mattlawck of StudioPress
8/3/2018 - 4:03 PM

Add Read More Link for Automatic and Custom Excerpts.

Add Read More Link for Automatic and Custom Excerpts.

<?php

//* Do NOT include the opening php tag shown above. Copy the code shown below.

//* Add Read More Link to Automatic and Custom Excerpts Site-wide
add_filter( 'the_excerpt', 'sp_read_more_custom_excerpt' );
function sp_read_more_custom_excerpt( $text ) {
   if ( strpos( $text, '[&hellip;]') ) {
      $excerpt = str_replace( '[&hellip;]', '<a class="more-link" href="' . get_permalink() . '">[Read More&hellip;]&hellip;</a>', $text );
   } else {
      $excerpt = $text . '<a class="more-link" href="' . get_permalink() . '">[Read More&hellip;]</a>';
   }
   return $excerpt;
}