Tech-Evangelist

Technical Articles, Musings and Opinions from Tech-Evangelist

  • Home
  • About
  • Guidelines
Previous article: 10 Ways to Speed Up a Website
Next article: Tips for Improving 3D Movie Viewing in Your Home Theater

Customizing Read More Links in WordPress

July 20, 2009 By Doogie - Copyright - All Rights Reserved

We have used WordPress for several years and have always been annoyed by the fact that the “Read More” or “Read the rest of this entry” link that displays when using excerpts on the home page, category pages and archive pages always jumped to the next block of text on a page using a bookmark link. We want the entire page to display, just like any other web page, and want users to start at the top. The solution has always required editing of the WordPress core code. WordPress 2.8 finally resolves this issue and editing of core files is no longer required.

WordPress 2.8 added the ability to modify the Read More link without having to modify the core files. Modifying the core files is always a nuisance and should be avoided whenever possible, because every time you upgrade WordPress, which could be 5 or 6 times per year, you have to modify the files again. The solution is found on a new WordPress codex page that includes other tips for modifying this link.

To remove the jump to the next block of text, the #more bookmark needs to be removed from the link leading to the post. To remove the bookmark, simply add the following function to the functions.php file found in your WordPress theme.

function remove_more_jump_link($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_jump_link');

Customizing the Read More Links

If is also easy to customize the text in the Read More link to say almost anything you want it to say. The Default theme that comes with WordPress uses “Read the rest of this entry”. To change the text in this message, find the the_content function call in the appropriate theme script. The function argument can be changed to anything you want to use.

<?php the_content('Read the rest of this entry »'); ?>

Removing the Read More Links
Sometimes you might want to take this one step further and remove the Read More links entirely. The title for the posts on the home page, category pages and archive pages is also a link to the post, so using the Read More link is redundant and unnecessary. The easiest way to remove the link is to simply modify the arguments in the the_content function call like the following.

<?php the_content('',FALSE,""); ?>

There are three arguments to be passed. The first is empty and denoted by two single quotes, followed by a comma, followed by the word FALSE, followed by a comma, and then two more single quotes.

Any time that WordPress can be customized without modifying core files is a plus. Kudos to the WordPress team for finally making this easier to do.

Filed Under: WordPress Tutorials

Categories

  • Affiliate Marketing
  • CSS Tutorials
  • FileZilla Tutorials
  • Home Theater
  • Internet Marketing
  • Internet Technology
  • Kindle Tips
  • MySQL Tutorials
  • Online Auction Tips
  • Paint Shop Pro Tutorials
  • PHP Tutorials
  • Tech News
  • Thunderbird Tutorials
  • Video Production
  • Web Site Development
  • WordPress Tutorials
follow me on Twitter
Content and images are copyrighted by Tech-Evangelist.com and others

© 2021 Tech-Evangelist.com - All Rights Reserved
Posted code samples are free to use. Do not reproduce or republish articles or content on another web site.

Privacy Policy : Terms of Use