IOM Partners of Houston

A comprehensive range of Houston Website Design Services now on offer from IOM Houston which is the market as well as segment leader in web design and development solutions through its professional team of website designers who possess years of industry s

How to Add Word Limits for Comments on Your WordPress site?

Comments are a good way to make your website more interactive.  They allow you to communicate with your visitors and also get their feedback. However, not all comments are useful for you. Certain comments do have a negative impact on your website’s popularity. A great way to get around this problem is to limit the length of comments on your WordPress site.

f:id:iomhouston:20160314151518j:plain

Why limit the length of comments?

As said before, there are some comments that might prove detrimental to your site. For example, comments which are usually of a few words length are generally spam and are posted on your site to get backlinks. On the other hands, comments which are quite long are generally complaints and you would not want to show them up on your website. It has been found that comments which are between 60 and 5000 characters are the best for your website.

f:id:iomhouston:20160314152135j:plain

How to limit the length of comments on WordPress site?

You can limit the length of comments by using a simple code snippet. You would just need to add a filter hook to preprocess_comment. This filter would be run before WordPress saves any comment to database and runs any pre-processing on the comments. If the length of the comment is below or above the permitted length it would show an error message.

You just need to add the following code in the functions.php file.

01 add_filter( 'preprocess_comment', 'wpb_preprocess_comment' );
 
 02
function wpb_preprocess_comment($comment) {
 04
    if ( strlen( $comment['comment_content'] ) > 5000 ) {
 05
        wp_die('Comment is too long. Please keep your comment under 5000 characters.');
 06
    }
 07
if ( strlen( $comment['comment_content'] ) < 60 ) {
 08
        wp_die('Comment is too short. Please use at least 60 characters.');
 09
    }
 10
    return $comment;
 11
}

Method 2 – Using a Plugin
If you are not so confident using code, you can also limit the comment length using a plugin. You can use a simple plugin called Control Comment Length plugin. Once you get the plugin installed, you just need to go to settings>>control comment length and then change the maximum and minimum number of characters in comments.

It is always advised to take the help of a reputed WordPress developer to make any necessary changes to your WordPress site. The leading Houston Web Design company would help you design the perfect WordPress site for your business. They have some of the most experienced web designers and web developers who enjoy a great deal of repute in the field of web design Houston. They are well versed in HTML and CSS coding and WordPress development and hence the leading names in the field of web design in Houston is the best bet for you. So take the help of these companies and design the perfect WordPress site for your business.