Screenshot

Wondering how to change the default excerpt word count length in a WordPress theme?

In this post, I’ll show you how you can quickly customize it on your own.

You’re probably thinking, “I’ll just get a plug-in for that!” However, it is actually easier to do this manually than using a plug-in.

We’re going to add a new function to your child theme. That way when you update your WordPress version, your site will retain your modifications.

Do not worry, this is easy.

If you are not familiar with PHP, all you have to do is cut and paste the simple code I wrote below into your functions.php file. You’ll want to use a plain text editor (like Sublime Text 2) or use the built-in editor in WordPress.

In your functions.php file, paste the following code to the end of the file (before the final “?>”).


/* Change Excerpt length */
function custom_excerpt_length( $length ) {
return 30;
}
add_filter( ‘excerpt_length’, ‘custom_excerpt_length’, 999 );

As of this writing, (WP 3.6), excerpts are set to display 55 words by default. In this example, I set the excerpt default word count to 30 (the settings on this blog).

For your site, just change the number “30” in the code to your preferred word count!

 Development, Featured, Web Design

, ,


Matthew's Blog
Home   Blog   LinkedIn   Contact Me
Connect on LinkedIn, Google+,
Current focus: App & Web Development
Preferred Environments: OS X, iOS, Xcode, Sublime Text
Current skills: SWIFT, Objective-C, iOS SDK, CoreData, CoreAudio, JavaScript, HTML5, CSS, Wordpress
Degree: Bachelors of Science in Computer Information Systems Technology
from PURDUE University


© Website by Matthew Fecher
Denver, Colorado, USA.

top