X

How to Add a Link to the Full Article from Excerpt in WordPress

Snippets by IsItWP

Do you want to add a link to the full article from horizontal ellipsis (3 dots) of your post excerpts? We already know how to change its length, but that ‘…’ could be improved to be more accessible by making it link to the full article.

Instructions:

Add the following to functions.php or in a site-specific plugin. Uncomment the latter return (and comment out the former) if you want to add the link!

<?php
add_filter('the_excerpt', 'new_excerpt_hellip');
function new_excerpt_hellip($text)
{
   return str_replace('[...]', '&hellip;[+]', $text);
   //return str_replace('[...]', '&hellip;<a href="'. get_permalink($post->ID) . '">[+]</a>', $text);
}
?>

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: Best WordPress Page Builders (Compared).

[code]ID) . '">[+]', $text); } ?>[/code]

Comments   Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!