I know it's three years late, but I found a better solution that it can even help me in the future:
First, clean the default excerpt more to remove the default ellipses [...]
:
function clean_excerpt_more() {
return '';
}
add_filter( 'excerpt_more', 'clean_excerpt_more' );
Then, we get the excerpt and add the link inline, into the same excerpt paragraph! (Most of the solutions above show the link out of the paragraph, in a new line).
function custom_the_excerpt( $excerpt ) {
global $post;
if( $post->post_excerpt ) {
// If the post has manual excerpt,
// it already has a point to end
// the paragraph, so we don't want
// the point + the ellipsis: ....
// Clean it!
$ellipsis = '';
} else {
$ellipsis = '...';
}
// Save the link in a variable
$link = $ellipsis . ' <a class="moretag" href="' . get_permalink( get_the_ID() ) . '">' . __( 'Read more »', 'starion' ) . '</a>';
// Concatenate the link to the excerpt
return $excerpt . $link;
}
add_filter( 'get_the_excerpt', 'custom_the_excerpt' );
Edit: A final note. You don't need to modify nothing else. Use the_excerpt();
normally to display the excerpt with the link.
Hope it helps to someone :)