DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

If you ever wanted to be able to set a maximum word count of post titles so your contributors will not define titles that are too long, the following recipe is for you. I’ll show you how you can easily set a maximum word count on post titles.

To apply this hack, simply paste the following in your functions.php file:

function maxWord($title){
    global $post;
    $title = $post->post_title;
    if (str_word_count($title) >= 10 ) //set this to the maximum number of words
        wp_die( __('Error: your post title is over the maximum word count.') );
add_action('publish_post', 'maxWord');

Thanks to Pippin for this great code!


Leave a Comment

Your email address will not be published. Required fields are marked *