Change the_content <!--more--> link in Wordpress

Change the_content link in Wordpress

December 10th, 2008

A handy little tip for Wordpress that will help you to remove the part of the link for reading more of an article.  By default this link will take you halfway down the page to continue reading.  Could be handy, but I prefer to start at the beginning of the page and find the jump down the page confusing.

Implementing the more link.

Just a quick note before we begin.  I have just upgraded to Wordpress 2.7 and from 2.6 and there were no problems with this when upgrading.

The more link is implemented by writing <!–more–> into the source code of your post.  At this point the post will be split into a section you can use as a preview and a the remaining section which will follow on in the whole post.

To create this link in your code insert the following

<?php the_content('Continue reading...', FALSE, ''); ?>

The the_content method accepts 3 arguments.  The first will allow you to customise the text in your link for clicking to the rest of your article. The second one, strip_teaser, sets whether or not the “more” link should be hidden (TRUE) or displayed (FALSE). The default is FALSE, which shows the link text. The last one, more_file, sets the link to the file that the “Read More” should link to, if you want it to be different. By default, it links to the current post file.

Change the functionality of the more link to take you to the top of the page

Now we have the content working but the link takes you half way down the post. To fix this we need to go into the file “wp-includes/post-template.php

In this file look for the line:

$output .= ' <a href="'. get_permalink() . "#more-$id">$more_link_text</a>";

Replace the above code with the following:

$output .= ' <a class="&quot;more-link&quot;" href="'. get_permalink() . ">$more_link_text</a>";

…and we’ve fixed the problem. You can edit the above code as you like to adjust the output to your requirements.

Tags:

Enjoy this article?

Your vote will help the site grow and allow me to produce more articles like this.

Leave a Reply