Would you like to know how to customize wordpress excerpts? An excerpt is a condensed version of your article that you may put on other important pages of your website or in a list of blog entries.
We’ll demonstrate how to edit your WordPress excerpts without using any code in this tutorial.
Want to Become a PRO? Join out WordPress Bootcamp
WordPress Excerpts: When and Why to Use Them
Let’s first discuss when it makes sense to use excerpts and why doing so is a great idea.
WordPress by default displays whole posts on your home page, blog page, and site archives.
This slows down your website and increases the chance that you’ll have duplicate material, which may be problematic for search engines.
Because you will only be loading a portion of each item, using excerpts will speed up page load speed. Consider using extracts on:
- if it displays blog posts, the front page of your website.
- Your many archive pages for tags and categories.
- if you have a static home page, your blog post page.
On pages like your home page, many WordPress themes are set up to use excerpts by default. You may have the choice to show complete articles or excerpts when using premium WordPress themes.
Why You Might Want to Customize WordPress Excerpts
WordPress will create an excerpt for you automatically if your theme supports them by default. WordPress only displays the first 55 words of your article by default, but many themes will display a few more.
What is wrong with it, then? Why don’t you just let WordPress generate the excerpt for you to save time?
Here is the issue. Whatever text appears at the top of your post will be the first line of the auto-generated excerpt. This is OK in some circumstances, but it doesn’t function well if you have anything to say before the introduction of your article.
So with that said, let’s look at several WordPress excerpt customization options. To jump to any method, use the links below:
- WordPress: How to Add a Custom Excerpt (Default)
- Modifying the Excerpt Length
WordPress: How to Add a Custom Excerpt (Default)
It’s easy to add a custom excerpt in WordPress. Create a new post or edit an existing one to start with.
You should be able to select “Excerpt” from the dropdown menu in the right-hand panel of the WordPress article editor. To move it lower, click the arrow there.
The excerpt box will appear after it expands. Here, you can type your personal post excerpt. We only repeated the first sentences of our post.
Note: Click the Screen Options tab in the upper right corner if you’re still using the old classic editor. Then select “Excerpt” by checking the box. Now, behind the area where you type your article, you will notice a space for your excerpt.
The custom excerpt for this post will now be used by your WordPress theme.
The Read More link is not displayed after the excerpt, as you can see. The link may not be included in custom excerpts, depending on the theme you select.
The reader may still access your complete content by clicking on the post title or featured picture.
Modifying the Excerpt Length
If you want to change the length of the excerpt on your site,you will need to write a code in your website’s function.php file.
This is the code you will need to enter:
add_filter(
'excerpt_length',
function ( $length ) {
// Number of words to display in the excerpt.
return 40;
},
500
);
By default, this code will limit the excerpt to 40 words. You can adjust the number on Line 5 to whatever is best for your WordPress Blog
Once you’ve set the length of the excerpt that you want then click on update button.
The shortened excerpts are now present wherever your theme displays them when someone visits your site.
Keep in mind that the WPCode snippet only functions with the automatic excerpts that WordPress creates.
Modifying the Length of Custom Excerpts
If you want to modify the length of custom excerpts, you will need to add separate php code in your website’s function.php file.
You will need to add this code:
add_filter( 'get_the_excerpt', function( $excerpt, $post ) {
$excerpt_length = 40; // Change excerpt length
$excerpt_more = '...<br><br><a href="' . get_permalink($post->ID) . '">Read More »</a>'; // Add ellipsis and 'Read More' permalink text when trimmed
if ( has_excerpt( $post ) ) {
$excerpt = wp_trim_words( $excerpt, $excerpt_length, $excerpt_more );
}
return $excerpt;
}, 10, 2 );
The number of words in your custom excerpt may be changed by changing the value for $excerpt length on Line 3.
Additionally, when the excerpt is trimmed, changing the text noted below on Line 4 will change the anchor text for the Read More link.
The custom excerpts are now shortened to the length you specified on Line 3 when you visit your site.
Conclusion:
In this article, we have learnt how to customize wordpress excerpts and previously we learnt how to switch to Classic Editor.
Now you know:
- how to modify length of excerpt.
- Customizing custom excerpts.
If you liked this article please make sure to follow us on social media and youtube.