Limit the word count in the post title
Are you looking for Limit the word count in the post title to trim your Post Title Length in WordPress? While there’s probably a plugin for this, we have created a quick code snippet that allows you to use wp_trim_words to trim your text in WordPress.
WordPress 3.3+ has a core function called
wp_trim_words(). This function will trim text to a specified number of words and return the result. Adding this snippet to your WordPress loop will let you easily trim the number of words displayed within the_content, the_excerpt, the_title or any other value you pass to this core function.
Instructions:
All you have to do is add this code to your theme’s PHP file where you want to show the title:
If continue sign "..." needed at the end of title
<?php echo wp_trim_words( get_the_title(), 10, '...' ); ?>
If continue sign "..." not needed at the end of title
<?php echo wp_trim_words( get_the_title(), 10 ); ?>
Parameters:
- $text
- (string) (required) Text to trim
- Default: None
- $num_words
- (integer) (optional) Number of words
- Default: 55
- $more
- (string) (optional) What to append if $text needs to be trimmed.
3 comments
MH
Mahmud Hossain
July 16, 2026
Well written. Bookmarked this for my team's reference. Looking forward to more content like this.
SB
Sumaiya Begum
July 15, 2026
Does this approach also work for larger datasets? Our team is dealing with something similar at scale.
RK
Rafiq Khan
July 14, 2026
Really insightful article! This is one of the clearest explanations I've come across. The examples make it very easy to understand.
AD
AdminAdminJuly 14, 2026Thank you Rafiq! Glad it was helpful.
