WordPress

Change End Excerpt In WordPress

Wordpress is a popular blogging software that allows you complete freedom on how you display the posts to your visitors.

It is common on most blogs to have a snippet of the post on the home page of the blog. Just like on this blog there is a excerpt of the posts on the home page, it will display the first 100 characters of the post then there will be a link for the visitor to view the whole page. In WordPress this is easily done by using the the_excerpt() function. The WordPress default will display the first 250 characters but you can change this to what ever you want by applying a filter to change the excerpt length.

But the default the_excerpt() function will end the snippet of the post with a [...], which isn't the best looking with your design, so you can change this with the following code snippet.

Copy the following into your functions.php file and you can change the [...] at the end of your excerpt.

/**
 * Replace the [...] wordpress puts in when using the the_excerpt() method.
 */
function new_excerpt_more($excerpt) 
{
	return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');
Back to top

Learn how to code with Treehouse

  • Learn projects with access to 1000+ videos
  • Practice live with our Code Challenge Engine
  • Get help in our members-only forums

Start with a 7 day free trial