Set maximum post title length

This bit of code will allow us to set a maximum word count to the post title.Adding this PHP code to the functions.php of your wordpress theme will set a maximum number of words that can be displayed within your post title.



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');

Leave a comment