I`m searching for a function to limit the number of characters a user can type into the headline field in the editor.
1 Answer
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>." ); }
– JohnJul 4, 2013 at 11:25