admin管理员组文章数量:1326099
i used this code for limit comment length
add_filter( 'preprocess_comment', 'wpb_preprocess_comment' );
function wpb_preprocess_comment($comment) {
if ( strlen( $comment['comment_content'] ) > 5000 ) {
wp_die('Comment is too long. Please keep your comment under 5000 characters.');
}
Now i need display in comment field, how many characters user already written. Is it possible do with php code into functions? Or do you know some plugin?
Any suggestions welcome.
i used this code for limit comment length
add_filter( 'preprocess_comment', 'wpb_preprocess_comment' );
function wpb_preprocess_comment($comment) {
if ( strlen( $comment['comment_content'] ) > 5000 ) {
wp_die('Comment is too long. Please keep your comment under 5000 characters.');
}
Now i need display in comment field, how many characters user already written. Is it possible do with php code into functions? Or do you know some plugin?
Any suggestions welcome.
Share Improve this question edited May 24, 2020 at 13:53 klvb asked May 22, 2020 at 20:34 klvbklvb 212 bronze badges 4- You mean the comment form in the blog posts? You want the number of available characters left to be updated as the user types? – Himad Commented May 23, 2020 at 0:27
- yes, some simple text as "1400 characters left" in the corner of field – klvb Commented May 23, 2020 at 1:13
- 1 You'd want to use jQuery for that, not PHP. – Tony Djukic Commented May 23, 2020 at 2:41
- And some idea how to do it in jQuery? – klvb Commented May 23, 2020 at 19:10
1 Answer
Reset to default 1I used this:
function wpb_countx() {
wp_enqueue_script('jquery');
?>
<script>
jQuery(function($) {
// configure
var comment_input = $( '#commentform textarea' );
var submit_button = $( '#commentform .form-submit' );
var comment_limit_chars = 1400;
// stop editing here
// display how many characters are left
$( '<div class="comment_limit_info"><span>' + comment_limit_chars + '</span> zbývá znaků</div>' ).insertAfter( comment_input );
comment_input.bind( 'keyup', function() {
// calculate characters left
var comment_length = $(this).val().length;
var chars_left = comment_limit_chars - comment_length;
// display characters left
$( 'ment_limit_info span' ).html( chars_left );
// hide submit button if too many chars were used
if (submit_button)
( chars_left < 0 ) ? submit_button.hide() : submit_button.show();
});
});
</script>
<?php
}
add_action('wp_footer', 'wpb_countx');
本文标签: jqueryHow to display comments length
版权声明:本文标题:jquery - How to display comments length 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742193927a2430726.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论