2

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

Ive search over the internet but nothing found.

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

Charles
  • 50,943
  • 13
  • 104
  • 142
Juliver Galleto
  • 8,831
  • 27
  • 86
  • 164

2 Answers2

4

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.

Regards.

Himanshu Jain
  • 444
  • 1
  • 8
  • 23
1

The following will limit the number of characters a user can enter in the admin area, i.e., when writing a post.

add_action( 'admin_head-post.php', 'so_13816272_limit_input_title' );

function so_13816272_limit_input_title(  )
{
    global $current_screen;
    // Not our post type, exit earlier
    if( 'post' != $current_screen->post_type )
        return;
    ?>
    <script type="text/javascript">
        jQuery(document).ready( function($) 
        {
            $('#title').keyup( function() 
            {
                var $this = $(this);
                if($this.val().length > 50)
                    $this.val($this.val().substr(0, 50));           
            });           
        });     
    </script>
    <?php 
}

If you want to do a word count, refer to this article and adapt the functions into the above code.

brasofilo
  • 25,496
  • 15
  • 91
  • 179