WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to limit the word count of the post title?

I searched over the internet but found nothing.

All I know is, only the content of the post can be limited or excerpted.

share|improve this question

There is a built-in function for that: wp_trim_words().

add_filter( 'the_title', 'wpse_75691_trim_words' );

function wpse_75691_trim_words( $title )
    // limit to ten words
    return wp_trim_words( $title, 10, '' );
share|improve this answer

simply use this where ever you want to display your title with limited words

<?php echo wp_trim_words( get_the_title(), 5 ); ?>

replace number 5 in above code with whatever number of words you need to display.


share|improve this answer
function limit_word_count($title) {
    $len = 5; //change this to the number of words
    if (str_word_count($title) > $len) {
        $keys = array_keys(str_word_count($title, 2));
        $title = substr($title, 0, $keys[$len]);
    return $title;
add_filter('the_title', 'limit_word_count');

You can put any kind of limit on almost anything you like, you just need the correct filter

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.