Disable or customize WP read more link
Quick snippet for customizing or disabling the WordPress “read more” link for the_excerpt()
.
The problem with the read-more link is that it’s included within the excerpt’s closing <p>
tag, which doesn’t work with all types of layouts. Fortunately there’s an easy fix for either disabling or customizing, just add the following slice of PHP to your theme’s functions.php file:
// customize read more link
add_filter('the_excerpt', 'wpmix_customize_readMore');
function wpmix_customize_readMore($output) {
$markup = substr($output,0,-5);
$markup .= '</p>';
return $markup;
}
As-is, this code will simply disable the read-more link, but it also works great for customizing with your own link markup (or whatever). For example, to replace the default markup with an ellipsis and custom read-more link, the function looks like this:
// customize read more link
add_filter('the_excerpt', 'wpmix_customize_readMore');
function wpmix_customize_readMore($output) {
$markup = substr($output,0,-5);
$markup .= ' <span class="more-link-ellipsis">[…]</span>';
$markup .= ' <a href="'. get_permalink($post->ID) . '" title="Continue reading: '.get_the_title($post->ID).'" class="more-link">Read more »</a></p>';
return $markup;
}
Another example, here’s the function modified to display the read-more link in its own paragraph:
// customize read more link
add_filter('the_excerpt', 'wpmix_customize_readMore');
function wpmix_customize_readMore($output) {
return $output .'<p><a href="'. get_permalink($post->ID) . '" title="Continue reading: '.get_the_title($post->ID).'" class="more-link">Read more »</a></p>';
}
This technique may also work with the_content()
by replacing the_excerpt
with the_content
in add_filter()
. Some tweaking may be necessary to dial it in.