How to Add Read More to WordPress Excerpts

So anytime we are asked to provide an enhancement to a WordPress Theme or WordPress install, we have decided to post our code up on our site to help out our fellow web developers and anyone who is trying to learn or maximize the functionality of WordPress.

A recent client purchased a Premium theme and contacted us to make some customizations and add functionality to the WordPress theme.  This particular client wanted the packaged widgets to display excerpts and not the pre-coded pulled content from posts.

The original code looked like this:

<?php the_content_limit(240, ‘read more &raquo;’); ?>

Great easy enough, all we had to do was take that out and add the following:

<?php the_excerpt(); ?>

Worked like a charm, but something was missing.  The client liked the automatic read more text and wanted that to remain as a built in function of the widget.  Well if this is the case you have a few options, here are two options below:

First you could add the following code:

<?php the_excerpt(); ?>

and add the following code directly below:

<a href=”<?php echo get_permalink(); ?>”> [ Read More → ]</a>

Or the other option is to add the following code to your functions.php file and it will automatically update all excerpts used in the WordPress install: (we chose this option)

<?php function excerpt_ellipse($text) {

return str_replace(‘[...]‘, ‘ <a href=”‘.get_permalink().’”>Read more…</a>’, $text); }

add_filter(‘the_excerpt’, ‘excerpt_ellipse’);

?>

 

References:

http://wordpress.org/support/topic/excerpts-no-read-more-link

http://codex.wordpress.org/Excerpt

 

Leave a comment if you have any questions!  Thanks for reading!

This entry was posted in Wordpress Tips, Wordpress Tutorials and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Wordpress Design & Development

    Denver wordpress development
  • Get a Free Quote