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.

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. 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. You may not have even read the except.

A solution

Add the following code to the relevant functions file in your theme, this is usually 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.

By Mark Hesketh

I'm a PHP Developer based in UK, building modern PHP web applications and writing about everything I learn.