Customize Excerpts

Excerpts can be a little bit confusing when considering other built-in WordPress features. They don’t have to be, though.

Post excerpts are automatic… period. They are implemented by a function in the WordPress core and they are not something that you activate in the Edit Post screen.

However, they can be edited on the Edit Post screen in the “Excerpt” meta box beneath the text editor (if you don’t see it, click the “Screen Options” tab in the top right corner of your Edit Post screen and check the “Excerpt” box… which is unchecked by default).

When excerpts are displayed on your blog, all formatting is stripped and the content is restricted to a certain length, bringing uniform to your posts.

This is a totally different feature from the more tag that can be used in the text editor to truncate an article at the exact point that you’d like. However, no formatting is stripped.

So, if you use the more tag, which is the page break (looking) button next to the spell check in your visual editor, anything you type above the placement of that more tag will display as-is in your post listing.

With that being said, using excerpts will override everything.

If excerpts are displayed, your only options that don’t require PHP (for things like excerpt length) are using the custom Excerpt field mentioned above or replacing the default ellipses […] at the end of your excerpt with a link.

If the more tag is used in a post, for it to display as a truncated article with full formatting, excerpts must be turned off.

If excerpts are turned off, posts will show in full length by default. This means you will need to place a more tag in every single published article if you want all of them to truncate.

Enough with the explanations, though. Let’s look at some code snippets.

Only paste PHP into the functions.php file of your child theme!

Change Excerpt length

Adjust the number “75” to anything you’d like. Remember, excerpts have no post formatting. So, the longer the excerpt, the bigger the sea of text for your visitors to drown in.

// Child theme excerpt length
function child_theme_excerpt_length( $length ) {
	return 75;
add_filter( 'excerpt_length', 'child_theme_excerpt_length', 999 );

Change Excerpt Ellipses

Again, you can change the ellipses […] to a link in your Volatyl Options. If that’s not enough, you can adjust the ellipses with the following code:

// Replace excerpt ellipses
function child_theme_new_excerpt_more( $more ) {
	return ' excerpt ending';
add_filter( 'excerpt_more', 'child_theme_new_excerpt_more' );

To make your own link instead of the Volatyl Options, use this:

// Replace excerpt ellipses with link to post
function child_new_excerpt_more( $more ) {
	global $post;
	return ' <a href="'. get_permalink( $post->ID ) . '">Read the Rest...</a>';
add_filter( 'excerpt_more', 'child_new_excerpt_more' );

The area is yours. Do with it what you will!

Return to docs