How to Change the Excerpt Length of Divi Blog Posts

by | Jun 11, 2016 | Blog, PHP

Sign up to receive all the latest themes, tutorials, tips & tricks from Divi Soup

How to Change the Excerpt Length of Divi Blog Posts

Recipe #18 follows on from the blog layout theme of recent recipes, but I have decided this week to show you how to change the excerpt length of Divi blog posts as it is something that I see asked quite often in the Divi Facebook groups.

The reason why this appears to be difficult is that Divi doesn’t use the WordPress built in blog layout, it has one all of it’s own which is how you are able to have the custom Divi blog module in the builder.

Now obviously you can set manual excerpts but what if you are importing a ton of existing content in to a new site? You don’t want to have to go into each post and add a manual excerpt to every single one, with this method you don’t have to.

If you haven’t yet checked them out yet you can read How to Create a Pinterest Style Blog Layout (Recipe #15) here, How to Create a Letterbox Style Blog Layout (Recipe #16) here, and How to Create a Large Thumbnail Style Blog Layout (Recipe #17) here.

So let’s get cooking!

ingredients

The Divi Theme from Elegant Themes

An active child theme (we are going to be editing a little PHP so a child theme is a ‘must have’ for this recipe)

FTP or cPanel access to upload your modified PHP files

Some existing blog content or sample blog content for testing purposes

cooking-time

This should take you around 10 minutes max.

preparation

There is not much prep for this recipe, just make sure you have the latest version of the Divi theme saved and unzipped somewhere on your computer as we are going to need a file from it. You will also want to BACK UP before you begin, it’s not a good idea to start editing PHP without a back up.

method

So the first thing we need to do is go into our unzipped Divi theme folder on our computer and navigate to Divi > includes > builder and then locate the file called main-modules.php.

How to change the excerpt length of divi blog posts tutorial

Copy the main-modules.php file and then paste it into the root of your child theme.

How to change the excerpt length of divi blog posts tutorial

Now open up the main-modules.php file from your child theme folder in your favourite text editor (I’m using Brackets by Adobe which is free for both Windows & Mac) and scroll down to line 11118 (at the time of writing this is accurate for the latest version of Divi, 2.7.5, for later versions the location may move so you may need to search a bit). The line you are looking for is truncate_post( 270 );

How to change the excerpt length of divi blog posts tutorial

270 is the number of characters, not words, the excerpt is set to display, change this number to whatever you want, but be careful not to mess with any formatting.  I am going to use 170 as that should fit nicely with the layout I am working with.

Be sure to save the file.

Next, open up your functions.php file from your child theme root folder (this file is automatically created with any child theme builder or plugin you use). Paste in the following code.

if ( ! function_exists( 'et_builder_add_main_elements' ) ) :
function et_builder_add_main_elements() {
require ET_BUILDER_DIR . 'main-structure-elements.php';
require 'main-modules.php';
do_action( 'et_builder_ready' );
}
endif;

 How to change the excerpt length of divi blog posts tutorial

Now save the functions.php file too.

Next you will need to open up your FTP program or cPanel and upload the modified functions.php and main-modules.php file to the root of your child theme folder.

How to change the excerpt length of divi blog posts tutorial

Ok, now lets check our blog posts. You may need to clear your browser and system caches before you will see the changes.

Here is what mine looked like to start with (270 characters).

How to change the excerpt length of divi blog posts tutorial

And here is what it looks like after changing the excerpt length (170 characters).

How to change the excerpt length of divi blog posts tutorial

Much better 🙂

And that’s it. you should now have a shorter (or longer if that’s what you chose) excerpt on your Divi blog posts.

If you found this helpful please leave a comment and subscribe to my newsletter for all my latest Divi related content. 🙂

Michelle X

Michelle Nunan is a multi-award winning marketer & trainer and freelance web designer as well as a wife and mother of two beautiful girls and one cheeky Black Labrador called Harley. Michelle has been building websites since the late nineties, back in the days of GeoCities and Napster, before the web was the wonderful place it is now.

Join me on Facebook

WP Theme FAQs
Divi Switch
WordPress Theme Editor
Stock Images for as little as $0.69 each
Elegant Marketplace - Divi Child Themes, Plugins and Tutorials
Elegant Themes

Other recipes you might like...

Pin It on Pinterest

Share This
pro-membership

Enter your details below to get notified of the launch and early bird pricing

You have successfully joined the waitlist!