What is WordPress Excerpt Length?

Harry P

Well-known member
Registered
Joined
Feb 3, 2015
Messages
447
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
Registered
Joined
Nov 26, 2016
Messages
565
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
Registered
Joined
Feb 25, 2015
Messages
520
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

Well-known member
Moderator
Hosting Provider
Joined
Mar 5, 2021
Messages
177
Points
16
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.
 

Harry P

Well-known member
Registered
Joined
Feb 3, 2015
Messages
447
Points
28

MooseLucifer

Well-known member
Registered
Joined
May 20, 2016
Messages
149
Points
28
MooseLucifer
Hey Harry,

my_excerpt_length is a function that you can use to change the default excerpt length in WordPress. You can do this by inserting code into the functions.php file of your theme. Here’s an example of how you can use it:

Code:
function my_excerpt_length ($length) {
    return 80;
}
add_filter (‘excerpt_length’, ‘my_excerpt_length’);
In this example, we’re setting the excerpt length to 80 words. You can change this number to any value you like. After making changes, press the Update File button.
 

allwebhost

New member
Registered
Joined
May 25, 2023
Messages
8
Points
1
The WordPress excerpt length refers to the length of the summary or brief description of a blog post or article that is displayed on the website's homepage, archive pages, or in search engine results. It determines how many words or characters are shown in the excerpt before it is truncated with an ellipsis (...) or a "Read More" link. The excerpt length can be controlled and adjusted through WordPress settings or by using custom code to define the desired length for displaying a concise preview of the content.
 
Newer Threads
Recommended Threads
Replies
17
Views
26,745
Replies
13
Views
5,836
Replies
5
Views
3,550

Latest Hosting OffersNew Reviews

Sponsors

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