free web page counters

How to Limit Comment Length in WordPress (Easy Tutorial)

Sedang Trending 1 minggu yang lalu

Do you want to limit remark magnitude successful WordPress?

WordPress comments promote discussions astir your blog station content. However, you whitethorn find that comments that are very little aliases overly agelong are not very helpful.

In this article, we will show you really to easy limit remark magnitude successful WordPress.

Limit Comment Length successful WordPress

Why Limit Comment Length successful WordPress?

An progressive remark area is simply a awesome measurement to build a organization astir your WordPress blog. Visitors tin springiness feedback, inquire questions, and connection their ain points of position connected nan topic.

However, not each comments are helpful.

We’ve been moderating WordPress comments for good complete a decade. In our experience, we’ve recovered that nan astir adjuvant comments are supra 60 characters and beneath 5000 characters successful length.

One-word comments are usually not very helpful. In astir cases, they are spam comments wherever nan writer conscionable wants a backlink from your site.

On nan different hand, agelong comments supra 5,000 characters are often rants aliases complaints. Sometimes, they are not moreover applicable to nan article.

Setting remark magnitude limits successful WordPress tin amended nan wide value of your comments and discourage spam comments. However, location is nary built-in measurement of doing this successful WordPress.

That being said, let’s return a look astatine really to power remark magnitude successful WordPress by mounting minimum and maximum limits.

You tin limit remark magnitude successful WordPress by adding codification to your functions.php file. However, support successful mind that nan smallest correction while entering nan codification tin break your tract and make it inaccessible.

That’s why we urge ever utilizing WPCode to insert codification snippets into your WordPress site. It is nan champion WordPress codification snippets plugin connected nan marketplace that makes it safe and easy to adhd civilization code.

First, you request to instal and activate nan WPCode plugin. For elaborate instructions, spot our step-by-step guideline connected how to instal a WordPress plugin.

Note: WPCode besides has a free version that you tin usage for this tutorial. However, upgrading to nan paid scheme will springiness you entree to much features for illustration a larger codification snippets library, conditional logic, and more.

Upon activation, sojourn nan Code Snippets » + Add Snippet page from nan WordPress admin sidebar.

Here, click nan ‘Use Snippet’ fastener nether nan ‘Add Your Custom Code (New Snippet)’ option.

Add caller snippet

This will return you to nan ‘Create Custom Snippet’ page, wherever you tin commencement by adding a title for your codification snippet. This sanction won’t beryllium displayed connected nan website beforehand extremity and tin beryllium thing you like.

Next, take nan ‘PHP Snippet’ action arsenic nan Code Type from nan dropdown paper successful nan correct area of nan screen.

Choose nan PHP Snippet action for remark magnitude limit

Once you person done that, simply transcript and paste nan pursuing codification snippet into nan ‘Code Preview’ box:

add_filter( 'preprocess_comment', 'wpb_preprocess_comment' ); function wpb_preprocess_comment($comment) { if ( strlen( $comment['comment_content'] ) > 5000 ) { wp_die('Comment is excessively long. Please support your remark nether 5000 characters.'); } if ( strlen( $comment['comment_content'] ) < 60 ) { wp_die('Comment is excessively short. Please usage astatine slightest 60 characters.'); } return $comment; }

This codification snippet useful by adding a select hook to preprocess_comment. This select is tally earlier WordPress saves immoderate comments to nan database aliases performs immoderate pre-processing connected submitted comments.

It checks nan remark magnitude and displays an correction connection if it is excessively short aliases excessively long. By default, nan remark limit is group to a minimum of 60 characters and a maximum of 5,000 characters successful this snippet.

However, to group your ain remark limit, conscionable switch nan number 5,000 successful nan codification pinch your maximum limit number.

Similarly, you tin switch nan number 60 successful nan codification to group a different minimum remark limit connected your WordPress website.

You tin besides alteration nan connection that will beryllium displayed connected your website erstwhile a personification exceeds aliases falls short of nan remark limit. Simply type nan condemnation you want to show aft nan wp_die lines successful nan code.

Edit remark limit snippet

After that, scroll down to nan ‘Insertion’ conception and take nan ‘Auto Insert’ mode.

The civilization codification will beryllium automatically executed connected your website upon activation.

Choose an insertion method

If you only want to limit remark magnitude connected circumstantial website pages, past you tin besides do that.

Simply scroll down to nan ‘Conditional Logic’ conception and toggle nan ‘Enable Logic’ switch.

After that, take nan ‘Show’ action from nan ‘Conditions’ dropdown paper and click nan ‘+ Add caller group’ button.

Enable nan Conditional Logic toggle

This will unfastened a caller tab wherever you must prime nan ‘Page URL’ action from nan dropdown paper connected nan left.

Next, type nan URL of nan page wherever you want to limit nan remark magnitude successful nan section connected nan right.

Now, nan codification snippet will only beryllium activated connected nan page pinch nan URL you person conscionable entered.

Type nan conditional logic

Scroll backmost to nan apical of nan page and toggle nan ‘Inactive’ move to ‘Active’.

Finally, click nan ‘Save Snippet’ fastener to shop your settings.

Save nan remark limit snippet

Now, erstwhile a personification types a remark that falls short of your minimum remark length, this connection will beryllium displayed connected their screens.

Users won’t beryllium capable to station a remark until it is astatine slightest nan minimum magnitude you chose.

An Error Message Is Displayed if a Comment is Too Short aliases Too Long

Similarly, erstwhile a personification types a remark that exceeds your maximum limit, this connection will beryllium show connected their screens.

This will thief trim rants and spam comments connected your website.

Message preview for a agelong comment

Bonus: Improve Comment Engagement connected Your WordPress Site

Controlling remark magnitude is conscionable 1 measurement to summation engagement successful your WordPress comments section. This is awesome for keeping visitors connected your tract for longer and tin moreover benefit your site’s SEO erstwhile users’ comments incorporate applicable keywords and adhd discourse to your content.

You tin besides easy further amended nan comments conception connected your website utilizing Thrive Comments.

The Thrive Comments WordPress plugin

It is nan champion WordPress comments plugin that comes pinch a dedicated moderation board, lets you lazy load comments, allows users to time off comments pinch their societal media profiles, and more.

Plus, nan instrumentality enables you to adhd an upvote/downvote functionality to trim spam and promote absorbing comments connected your website.

Thrive Comments moreover lets you characteristic encouraging comments astatine nan apical and hide violative aliases irrelevant comments astatine nan bottommost of nan chat section.

Feature remark from dropdown menu

This allows you to reward users who are adding nan astir worth to nan chat while politely discouraging different users from leaving unhelpful comments.

For elaborate instructions, you whitethorn want to spot our tutorial connected how to characteristic aliases hide comments successful WordPress.

We dream this tutorial helped you study really to limit remark magnitude successful WordPress. You whitethorn besides want to study how to summation your blog traffic aliases cheque retired our database of the champion WordPress plugins to turn your site.

If you liked this article, past please subscribe to our YouTube Channel for WordPress video tutorials. You tin besides find america on Twitter and Facebook.

Disclosure: Our contented is reader-supported. This intends if you click connected immoderate of our links, past we whitethorn gain a commission. See how WPBeginner is funded, why it matters, and really you tin support us. Here's our editorial process.

Editorial Staff

About nan Editorial Staff

Editorial Staff astatine WPBeginner is simply a squad of WordPress experts led by Syed Balkhi pinch complete 16 years of acquisition successful WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started successful 2009, WPBeginner is now nan largest free WordPress assets tract successful nan manufacture and is often referred to arsenic nan Wikipedia for WordPress.