Adding custom excerpts to your WordPress site is easy. Adding custom “Continue Reading” links to these excerpts is slightly more difficult. In this tutorial I will demonstrate three methods on adding “Continue Reading” links to each post in the Archive view. This will require you to dive into some PHP files, but I will also mention a plugin that will accomplish this same task. The first method is the hardest and the last one (uses a plugin) is the easiest. If all else fails, visit the link at the end of this post for a long read-through in the WordPress Codex. Enjoy.
“Continue Reading” Links with function.php (Hard)
- Open your theme’s function.php file
- Go down to line 327 or search the phrase, “Continue Reading”. When searching go to this line.
- In this line of code you will see,
return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span>→</span>', 'twentyeleven' ) . '</a>';
- Replace “Continue Reading” with your own phrase.
“Continue Reading” Links in a custom Theme (Easy)
Note: This method is for those of you who can’t solve the problem by editing the function.php file. If you are building with the older Twenty Ten Theme, you will have to open the loop.php file instead of the content.php file that is found in the newer Twenty Eleven Theme
- First, open the content.php file found in your theme’s main directory.
- Go down to line ~35 that contains, “is_search()”
- Edit this line and add the following,
<?php if ( is_search() | is_category() ) : // Only display Excerpts for Search and Category Posts ?>
- The code following these if statements will now be activated only when the current page is a search page or is a category page. Also, the following code contains a div.entry-summary element. This section of code is only displayed on archive pages that look for summaries.
- Below this new conditional code, you will also notice a line that reads, “the_excerpt()”
- At the end of this line of code, hit enter/return to give yourself some space for some new code.
- Add this line of code,
<p><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">Keep on reading...</a></p>
- You can style this link by applying new styles to the .read_more class.
- You are now finished. Feel free to change the text of the link, “Keep on reading” to something memorable or more applicable to your site. Try not to use the default or a phrase common on other sites. People appreciate the effort to be more unique.
Using a Plugin to Add a Custom “Continue Reading” link (Easiest)
If you do not like the outcome of your custom made “Continue Reading” link, and you simply can’t get the CSS to display the link in a certain way, you may want to try a plugin. My personal favorite is the Advanced Excerpt Plugin. This plugin has a great menu, let’s you control what HTML tags are allowed in an excerpt, and allows you to add your own “Continue Reading” link. As long as you have a base install of the default Twenty Eleven or Ten themes, this plugin will automatically hook on to the_excerpt function. This means, everything is automated. However, if you want to use this plugin, and manipulate the_advanced_excerpt() hook, you can do that too. Just check the bottom of the plugin’s FAQ.
If you want to know more, feel free to read the WordPress Codex page on the Continue Reading Link.