很多读者在你的WordPress博客留言都是紧紧为了一个外链,所以他们很忙,随便发个“好文章”“顶一个”这样毫无意义的评论,虽然你可以手动删除他们,但是如果你的网站很受欢迎,删除评论也是很耗时间的!
倡萌建议限制你的WordPress站点评论内容的最小字数,这样应该是可以避免不少简短的评论。将下面的代码添加到当前WordPress主题的 functions.php 文件:
add_filter( 'preprocess_comment', 'minimal_comment_length' );
function minimal_comment_length( $commentdata ) {
$minimalCommentLength = 20;
if ( strlen( trim( $commentdata['comment_content'] ) ) < $minimalCommentLength )
{
wp_die( '抱歉,您的评论太短了,请至少输入 ' . $minimalCommentLength . ' 个字!' );
}
return $commentdata;
} |
add_filter( 'preprocess_comment', 'minimal_comment_length' );
function minimal_comment_length( $commentdata ) {
$minimalCommentLength = 20;
if ( strlen( trim( $commentdata['comment_content'] ) ) < $minimalCommentLength )
{
wp_die( '抱歉,您的评论太短了,请至少输入 ' . $minimalCommentLength . ' 个字!' );
}
return $commentdata;
}
注:请根据自己的需求修改第三行的数字。
方法解析:评论内容保存到数据库前,使用 preprocess_comment 过滤器来检查评论内容。通过 strlen() 函数计算评论内容的字数,如果小于限制的字数,就通过 wp_die() 函数访问提示信息!
来源:
https://www.wpdaxue.com/set-wordpress-minimal-comment-limit.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_33263.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57