How to remove hash from the “Read More” link

Posted By Sourabh Agrawal | May 06, 2020

If you are using WordPress’s default “Read More” or simply “more” block, you were facing this issue. So, here I will share you the solution to remove that hash link.

Understand It:

First of all, here we need to know why user want to remove this, or what actually this link do?

So, if you use the “more” block or “Read more” block, you might have noticed that when user click on the Read more button in the blog listing page then on the detail page, automatically, it scrolls to the section where you have added the “more” link.

We can not say it is useless or useful in a generic way because for every website the scenario may be different.

For example, if you are using the same content before the more link in listing and details page both then it make no sense for end user to read the content again. while, if you want user to read the content from the first line, you have to remove the additional hash from the URL.

<blog post link>/#more-<id>

Solution:

In order to remove this more link, you can add this simple code in the functions.php of your current theme:

function remove_read_more_link( $url ) {
$url = preg_replace( '|#more-[0-9]+|', '', $url );
return $url;
}
add_filter( 'the_content_more_link', 'remove_read_more_link' );

This peace of code you can use in the functions.php and it will automatically remove the extra hash value from the URL.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Sourabh Agrawal - WordPress Developer

Sourabh Agrawal

An Interactive Web Engineer

I am a WordPress developer with the hands-on experience with front-end techniques as well as the backend coding. I love creating new websites, optimizing them for performance and front-end detailing. I am graduated from the University Institute of Technology, RGPV in 2011 with a Bachelor of Engineering in Information Technology.

0
Would love your thoughts, please comment.x
()
x