Hi I am trying to make the post content (Description) mandatory or set minimum length for the content in wordpress. How do I do that?
I was trying this.
function display_short_error_message($messages)
{
global $post;
$content = $post->post_content;
if (str_word_count($content) < 100 ) {
$error_message = 'Post Should be at Least 100 Words';
add_settings_error('post_short_error', '', $error_message, 'error');
settings_errors( 'post_short_error' );
$post->post_status = 'draft';
wp_update_post($post);
return;
}
return $messages;
}
add_action('post_updated_messages', 'display_short_error_message');
I want to show the error message only when user clicks on publish.
Please help. Thanks in advance.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire