0

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

  • 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
0

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.

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.