Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I`m searching for a function to limit the number of characters a user can type into the headline field in the editor.

share|improve this question
1  
What do you mean by headline field? Can you explain it a bit more? –  Vinod Dalvi Jul 4 '13 at 10:30
    
I`m talking about the editor field, where you type in the headline, the title of your article or page. –  John Jul 4 '13 at 11:10

1 Answer 1

up vote 0 down vote accepted

You could add this function :

add_action('publish_post', 'wpse_105297_max_char');
function wpse_105297_max_char() {
   global $post;
   $title = $post->post_title;
   if (strlen($title) >= 100 )
    wp_die( "The max lenght is 100 for title" );
 }

This will prevent users from using too much longer titles.

share|improve this answer
    
Thank you. This works pretty well. Just added some usability. add_action('publish_post', 'wpse_105297_max_char'); function wpse_105297_max_char() { global $post; $title = $post->post_title; $id = $post->ID; $url = $bloginfo->url; if (strlen($title) >= 100 ) wp_die( "The max lenght is 100 for title<br /><br /> <a href=\"$url/wp-admin/post.php?post=$id&action=edit\">back to edit</a>." ); } –  John Jul 4 '13 at 11:25

Your Answer

 
discard

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.