How to Add a Character Counter to the WordPress Excerpt Box

How to Add a Character Counter to the WordPress Excerpt Box

If you’re a regular reader here on the WPMU DEV Blog, you may have noticed a few changes lately, namely our site design.

Our blog homepage is now a colorful collection of our most recent articles, complete with custom illustrations drawn by our talented design team. We’ve ditched sidebars and other distractions to improve the reading experience. We hope you like it.

Now, getting to the point of today’s Weekend WordPress Project: each article listing on the homepage now features a custom excerpt, rather than the first few paragraphs of the post. The only problem with this is that writing a custom excerpt that perfectly fits the space can be a challenge.

Today, I’m going to show you how to add a character counter to the excerpt meta box in the backend of WordPress.

Adding a Character Counter to Excerpts

When we first started using our new site design I was forever having to edit custom excerpts on posts because they were always too long for the space.

In searching for a solution, I came across this fantastic snippet at Stack Exchange. Simply add the following code to your functions.php files, or create your own plugin for it if you prefer:

And here’s what it looks like in the backend of WordPress when you’re editing posts:

Excerpt character counter
A character counter lets you keep track of the length of your excerpts.

You can change the maximum number of characters in any excerpt by changing the “500” in the code.

Why Would You Need a Character Counter?

Many themes have a specific requirement for how long excerpts should be. If you want your excerpts to display nicely without being cut off mid-sentence, having a character counter allows you to ensure your excerpt length is under a certain number of characters.

For sites like ours, having a character counter is certainly a useful feature.

Do you use custom excerpts on your site? What other kinds of Weekend WordPress Projects would you like to see on our blog? Let us now in the comments below.