WordPress Excerpt Customise – the_excerpt()

This article is a collection of snippets that can be used to modify the look and feel of excerpts on your WordPress Theme, to use any of these snippets copy and paste them into your functions.php file within your themes directory.

Change WordPress Excerpt Length

The following snippet allows you to customise the length of excerpt that will be displayed.

function jc_excerpt_length($length) {
    return 150;
}
add_filter('excerpt_length', 'jc_excerpt_length');

Change WordPress Excerpt Link Text

The following snippet will remove the […] link on the end of excerpts and replace it with the text Read More, that link to the article.

function jc_excerpt_more($more) {
	global $post;
	return '... <a class="moretag" href="'. get_permalink($post->ID) . '">Read More</a>';
}
add_filter('excerpt_more', 'jc_excerpt_more');

WordPress More Tag Not working in page template

Recently when working on a WordPress theme, after a bit of head scratching and alot of coffee, I had managed to come up with a solution to getting the more tag to work.
The More Tag is only supposed to use on index pages, but if you want to get it to work on page tempaltes or single pages add the following before the output of the_excerpt().

<?php
global $more;
$more = 0;
the_excerpt();
?>


Liked this article? help spread the word.