Hi all is there a way I can limit the length of comment_content in WordPress. I am creating a view of the last 5 comments of a page but want to limit the length.
This is the code I have so far:
<?php $args = array ( 'post_id' => '225', 'number' => '5', 'orderby' => 'date', 'order' => 'DESC', 'comment_approved' => '1' );
$comments = get_comments($args);
foreach($comments as $comment) :
echo('<div class="sidebarNewsTitle">'. $comment->comment_author . ' said : "' . strip_tags($comment->comment_content). '..."</div>');
endforeach;
?>
Reference:
http://clonetemplates.com/codex/limit-minimal-length-comment-content-wordpress.html/
http://codex.wordpress.org/Plugin_API/Filter_Reference/preprocess_comment
I guess you could try to limit length of comments with
wp_trim_words()
function which allows you to set the character/words limit for a specific block of content.To learn more about this function check this article.
But it is better to make your users aware of the limit, so using this plugin would probably be a better choice.
With this plugin you set:
There is a cool, new plugin with that you can set the minimum and maximum texts for comments. You can also edit the texts. Its called “Control Comment Length”
Check it out at http://greenitsolutions.at/control-comment-length-wordpress-plugin-by-greenitsolutions-at/ or on wordpress.org