Removing anchor links from 'read more' links in Wordpress
By default WordPress will add an anchor link to the end of your ‘Continue reading’ links, when using the More Tag.
By default WordPress will add an anchor link to the end of your ‘Continue reading’ links, when using the More Tag.
This means when your visitor clicks to view your post in full, they will be taken straight to the point in which the more tag appears. This is useful in some respect as it means the visitor isn’t reading the first couple of your paragraphs twice.
Personally, I don’t like it however. To me it feels a bit unexpected as if you’ve been taken to the wrong page/post as there’s no reference to what you had been initially reading such as the post title, or any imagery that might have been displayed.
A solution Add the following code to the functions.php file in your theme’s folder. (/wp-content/themes/themename/functions.php)
function remove_more_anchor($link) {
$offset = strpos($link, '#more-');
if ($offset) {
$end = strpos($link, '"',$offset);
}
if ($end) {
$link = substr_replace($link, '', $offset, $end-$offset);
}
return $link;
}
add_filter('the_content_more_link', 'remove_more_anchor');
This simple bit of code will remove the anchor link completely, taking your visitor to the post as if they had clicked the title.
Let me know if you have any suggestions to improve the code, or know an alternative solution.
Like this post? You can subscribe via RSS or e-mail for more. I also frequent Twitter and Google+.