Sarathlal N

Modify excerpt length & more tag – WordPress

In WordPress, it have ability to display automatically fetched excerpt for search result, index & archive pages. But in default, the excerpt length is limited with in 55 words.

If we like to modify this excerpt length, we can easily achieve this by adding a simple function & filter in our child theme’s function.php file.

// Changing excerpt length
function new_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');

From now, our excerpt length will be 100 words.

Modify more tag

At the end of each excerpt, WordPress display some more tag like [...] etc. We can also modify this more tag by another simple function & filter.

// Changing excerpt more
function new_excerpt_more($more) {
return '<span class="continue-reading"> <a href="' . get_permalink() . '">Continue Reading »</a></span>';
}
add_filter('excerpt_more', 'new_excerpt_more');

We just want to copy & paste above code in to our child theme’s function.php file. Try this code & view the changes.

Looking for a skilled WordPress/WooCommerce developer? I'm currently available for freelance, contract, or full-time remote opportunities! Let's create something amazing together. Send me a quick message, and I'll respond within 24 hours!

Recent Posts

  1. Automating Code Linting with GitHub Actions for WordPress Plugins
  2. Comprehensive Guide to Linting PHP, JavaScript, and CSS in WordPress Plugins Using Composer
  3. The Ultimate Guide to Indexing in Database Design
  4. Understanding 'update_meta_cache' in WordPress - When to Use It, When Not to, and Its Impact on Database Queries
  5. A Guide to Configuring JavaScript and SCSS Paths in WordPress Plugins with @wordpress/scripts

Your Questions / Comments

If you found this article interesting, found errors, or just want to discuss about it, please get in touch.