This question came across the PublishPress support desk this week:
Do you know how to set a maximum character length on the excerpt field? I need to be the point of entry, rather than when displaying it on the frontend. I want to force the user to write an excerpt of a certain length.
Why Restrict the Excerpt Length
Excerpts are commonly used in theme. You may seem them used on the front page or on “Blog” pages. Any time you don't have space for the whole post, you may want to use a short excerpt.
However, there is no fixed length for WordPress excerpts, and this can be a problem. For example, the user in our support desk had designed a front page with room for a 50 character summary of each post. They needed to make sure their authors entered as close to 50 characters as possible.
When you're writing a WordPress post, the excerpt box is quite small. Visually, you can see 2 or 3 lines of text. However, if your write text to go over 2 lines, WordPress will show a scrollbar for the box. There is no practical limit to the excerpt length.
Restrict the Excerpt Length in the Admin Area
First, we'll show to control the excerpt when authors are writing posts. You can force your authors to include an excerpt. You can also control the maximum and minimum number of characters in the excerpt.
You can do this with the PublishPress Checklists plugin.
- After installing the PublishPress Checklists plugin, go to Checklists > Settings.
- Scroll down to the “Number of characters in excerpt” row.
- Choose “Required” from the dropdown.
- Enter a “Min” and/or a “Max” setting in the right column. In the image below, users must enter between 50 and 60 characters.
- This will now be one of the items that authors must complete before publishing.
Now when someone goes to write a post, this is what they'll see in the sidebar:
If you don't fix this checklist item, it will be impossible to publish the post:
Once you have entered the correct number of characters, the red X will turn into green check mark. You can publish this post.
Hopefully this tutorial helps you control the excerpts on your site. It is also possible to add code to the front of your site site automatically cut your excerpts at a certain length. However, that also risks creating excerpts that don't make sense because of missing words. This approach we've outlined will ensure that every post on your site has a high-quality excerpt.