WordPress编辑器中的最少字符数



是否可以在WordPress编辑器中设置最小字符数,这意味着在遵守最小字符数之前无法发布文章?

打开您的functions.php文件或您编写自定义PHP代码的任何其他位置并粘贴以下内容:

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); // Place post in Draft status
return;
}
return $messages;
}
add_action('post_updated_messages', 'display_short_error_message');

post_updated_messages- 这会重定向到一个函数,在该函数中,我们只需提取帖子的长度,并将其与最小长度进行比较。

最新更新