我们辛苦收集的内容免费开放下载,仅仅只需评论应该不过分吧?但是我发现很多朋友评论一两个字,特别的敷衍,就这样完全不管我的想法, 所以我就想要限制文章评论当中的最少字数。
我在百度上面搜索这么一段代码,自己也使用过,确实有效果,现在分享出来:
添加在 wordpress 主题的的 function.php 文件中
add_filter( 'preprocess_comment', 'minimal_comment_length' );
function minimal_comment_length( $commentdata ) {
$minimalCommentLength = 40;
if ( strlen( trim( $commentdata['comment_content'] ) ) < $minimalCommentLength )
{
wp_die( '抱歉,您的评论太短了,请至少输入 ' . $minimalCommentLength . ' 个字!' );
}
return $commentdata;
}
function lxtx_set_comments_length($commentdata) {
$minCommentlength = 100; //最少字數限制,建议设置为5-10个字
$maxCommentlength = 2200; //最多字數限制,建议设置为150-200个字
$pointCommentlength = mb_strlen($commentdata['comment_content'],'UTF8'); //mb_strlen 一个中文字符当做一个长度
if ( ($pointCommentlength < $minCommentlength) && !is_user_logged_in() ){
err('抱歉!您说的内容太少了,请给我讲个' . $minCommentlength .'个字的笑话(目前字数:'. $pointCommentlength .')【登录后无此限制】');
exit;
}
if ( ($pointCommentlength > $maxCommentlength) && !is_user_logged_in() ){
err('对不起,你的文采太好了,你的笑话太长了,我只要' . $maxCommentlength .'个字的笑话!(目前字数:'. $pointCommentlength .')【登录后无此限制】');
exit;
}
return $commentdata;
}
add_filter('preprocess_comment', 'lxtx_set_comments_length');
使用方法
添加在 wordpress主题的的 function.php 文件中即可
标题:WordPress纯代码控制文章回复/评论最少字数
分类:WordPress教程
链接:https://www.wpjc.net/1149.html
版权:wpToo教程网(wpToo.com)所分享发布内容,部分为网络转载,如有侵权请立即联系我们,我们第一时间删除并致歉!
第三方发生的发是的dsdsf
水电费水电费把电饭锅
地方是将尽快尽快水电费就ww2。mathworks.cn/matlabcentral/profile/authors/23638799 ww2。mathworks.cn/matlabcentral/profile/authors/23638809
地方是将尽快尽快水电费就ww2。mathworks.cn/matlabcentral/profile/authors/23638799 ww2。mathworks.cn/matlabcentral/profile/authors/23638809 ww2。mathworks.cn/matlabcentral/profile/authors/23638823 ww2。mathworks.cn/matlabcentral/profile/authors/23638835 ww2。mathworks.cn/matlabcentral/profile/authors/23638847 ww2。mathworks.cn/matlabcentral/profile/authors/23638858 ww2。mathworks.cn/matlabcentral/profile/authors/23638868 ww2。mathworks.cn/matlabcentral/profile/authors/23638883 ww2。mathworks.cn/matlabcentral/profile/authors/23638895 ww2。mathworks.cn/matlabcentral/profile/authors/23638904 ww2。mathworks.cn/matlabcentral/profile/authors/23638914 ww2。mathworks.cn/matlabcentral/profile/authors/23638923 ww2。mathworks.cn/matlabcentral/profile/authors/23638935
hydroxychloroquine where to buy https://aralenhcl.com/
plaquenil pill plaquenil for sale