Skip to content

Instantly share code, notes, and snippets.

@studiopress
Last active April 16, 2019 14:23
Show Gist options
  • Save studiopress/6091191 to your computer and use it in GitHub Desktop.
Save studiopress/6091191 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment