A post excerpt is that shortened version of the post content that shows up under each post title in a blog or archive page. For WordPress users, the use of the term “excerpt” usually refers to one of three different things – manual excerpts, automatic excerpts, or teasers.
Manual excerpts can be added “manually” in the excerpt text box when editing a single post. Automatic excerpts are generated “automatically” when your theme uses the tag the_excerpt() in the post template (This is what Divi uses by default). Teasers are what is displayed if you use the “more tag” inside of your post and your theme uses the tag the_content() in the post template.
In this post, I will be showing you how to change the length of Divi’s automatic excerpts, whether you are using the Blog Module or standard blog template to display your posts. I will also show you how to generate manual excerpts for your individual posts.
The default length of Divi’s blog post excerpts is 270 characters.
Changing the default excerpt length for your blog page and category page requires a modification to Divi’s index.php file.
Add a copy of the index.php file to your child theme. If you don’t have a child theme installed, your first task will be to create one.
Open the index.php file using your text editor and find the following snippet of code:
Change the number “270” to whatever you want the character length of your excerpt to be. If you want the excerpt to have a character length of 470, replace the code with the following:
Save your file and go check out your blog post page and/or category page to see the new excerpt length in place.
If you are using the blog module for your blog page, changing the automatic excerpt length requires a modification of the main-modules.php file in Divi’s theme files.
Once again, the first step, (if you haven’t done it already) will be to create a child theme so that future updates to your theme won’t override your customizations. Once you have your child theme created and active on your site, you need to redefine and move the blog module code to the child theme. To do this, create a new folder in your child theme folder called “custom-modules”.
Inside the new “custom-modules” folder, create a new file called “cbm.php”
Inside your cbm.php file, insert the following (slightly modified) copy of the code that controls the blog module originally found in the main-modules.php file (make sure to include the opening php tag at the top of your file before the following code):
Note: this is a scrolling box of code. You’ll need to select and drag to get it all.
Find the following line of code that designates the length of the excerpt:
Notice the number value “270”. This is the current number of characters allowed for you your excerpt length. If you want a longer excerpt, replace the number “270” with a larger number like “470”. The new line of code should look like this:
Now that your cmb.php file is in place, go back to your child theme folder and add a new file called “functions.php”.
Open the functions.php file and insert the following code (make sure to preface the code below with the opening php tag):
Once the new function.php file is in place, check out your blog page to see the new excerpt length increased.
This change will affect both the grid and full width layout of the blog module.
Sometimes you need to completely customize your excerpt for a post to make sure the content and length is exactly what you want. This is easy to do with Divi.
First you need enable the use of excerpts. Go to Divi → Theme Options and under the general settings, click to enable the option “Use excerpts when defined”.
When editing your post, find the Excerpt text box under the WYSIWYG text editor. Enter a custom excerpt inside the text box.
Whatever content you enter inside the Excerpt text box (no matter what length) will be displayed as the excerpt for that specific post.
There are a number of reasons to change the length of excerpts. The reason may be purely aesthetic or it may be a way to boost your content strategy. Whether you are using the Divi Blog Module, a standard blog page, or manual excerpts, I hope this tutorial will help you take more control over your blog content.
I look forward to hearing from you in the comments.