What is WordPress Excerpt Length?

Harry P

Well-known member
Joined
Feb 3, 2015
Messages
376
Points
28
I am wanting to trimming text in post description on my Wordpressb blog, I searched and found this command my_excerpt_length and don't know how to use it. Can anyone help me a guide?
 

Dr. McKay

Well-known member
Joined
Nov 26, 2016
Messages
514
Points
28
WordPress excerpt length is like its call name. It is part of the post that links to the full article. It is used to engage readers and make them want to read more. It helps to highlight the main points of the content because sometimes the title is not enough to grab the viewer's attention.

By default, WordPress limits the excerpt to the first 55 words of a post.

When using the classic WordPress editor, excerpts can be automatically added to the content by pressing the Read More button. It will add <!–more–> to the HTML, and you can see it in the HTML editor. You can also enter a custom message like <!–more Continue Reading!–>..

Also, you can change the length of the snippet as you like. Increasing the text length can draw the reader's attention to the article.

There are different ways to change the snippet length, I will guide you right here.

How to change snippet length?
The two most common ways to change WordPress excerpt length are manually or using a WordPress plugin.

Change Snippet Length in WordPress Manually
The manual method will involve tweaking the code. However, you do not need to have in-depth knowledge of programming languages to do this.

Here are the steps by which you can change the length of the snippet yourself:

Hover over the Appearance tab and select Theme Editor.

Open the functions.php file and insert the code:

Code:
function my_excerpt_length($length){
return 80;
}
add_filter('excerpt_length', 'my_excerpt_length');
Change the word limit from 80 to any number you like and hit the Update File button.

For some themes, like Twenty Sixteen WordPress, you just need to edit the content.php file. Follow the instructions below:

While you're still in the Theme Editor, scroll down to template-parts. Under this heading, click on the content.php file.

Code:
<div class="entry-content">
<?php
Add the following code just below them:

Code:
if ( is_home() || is_category()||is_archive()){
the_excerpt(‘‘);
}else{
Find the sentences:
Code:
?>
</div><!-- .entry content -->
Then insert the following line above them:

Code:
} // end of if statements
Click Update File

and done!

Hope that helps!
 

Maxoq

Well-known member
Joined
Feb 25, 2015
Messages
468
Points
28
Agree with Dr. McKay but some Wordpress theme use their own function to replace WordPress Excerpt so you may need to check their codes to use if it did.
 

S4 Hosting

Moderator
Staff Member
Joined
Mar 5, 2021
Messages
57
Points
6
Another option is just to write a custom excerpt for each post before you publish it, gives much better control over the content and you can keep it to the length you want.
 
Newer Threads
Latest Threads
Replies
1
Views
26
Replies
1
Views
37
Replies
5
Views
48
Replies
0
Views
49
Replies
2
Views
56

Latest postsNew threads

Sponsors

Latest Blog ArticlesMost Viewed Threads

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top