Skip to content

Instantly share code, notes, and snippets.

@nfsarmento
Last active October 30, 2018 14:39
Show Gist options
  • Save nfsarmento/348274efab13e5aa1f9d0fecb567c9b4 to your computer and use it in GitHub Desktop.
Save nfsarmento/348274efab13e5aa1f9d0fecb567c9b4 to your computer and use it in GitHub Desktop.
"Read more" link to post excerpts of custom post types
/**
* Adds a custom "Read more" link to post excerpts of custom post types.
* Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and "Read more".
*
* https://www.nuno-sarmento.com
*/
function ns_cpt_excerpt_more( $more ) {
global $post;
$anchor_text = 'Read more';
if ( 'YOUR_CUSTOM_POST_TYPE_NAME' == $post->post_type ) {
$more = ' &hellip; <a href="'. esc_url( get_permalink() ) . '">' . $anchor_text . '</a>';
}
return $more;
}
add_filter('excerpt_more', 'ns_cpt_excerpt_more');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment