Limit Number of Words in Post Title

If you want to limit the number of words in the post title, you can use this snippet:

function wpkb_limit_title_words($title){
    global $post;
    $title = $post->post_title;
    $max_number_of_words = 10; // Modify 
    if (str_word_count($title) >= $max_number_of_words )
        wp_die( __('Error: Your post title contains too many words.') );
}
add_action('publish_post', 'wpkb_limit_title_words');