Limit the Length of Comments Left on Your Blog with this Plugin
This new WordPress plugin provides a configurable limit on the length of comments left in the comment form, with a character countdown displayed for the user and dynamically updated with each keypress.
IMPORTANT UPDATE: This plugin now has a newer version! For information on the version 1.2 release, please see the update announcement here: “WordPress Comment Length Limiter Plugin Updated”. For the 1.1 release, please see: “New Version of Comment Length Plugin Adds Anti-Spam Features”.
Why a WordPress Plugin?
As I mentioned in the announcement for my previous plugin release (see “Greg’s Threaded Comment Numbering Plugin for WordPress”), we run WordPress blog software in several areas of the site — in the Ask the Psychologist section, in our book reviews, and here in our main blog. We use many bits of custom code to add new features to our blogs, and to help our systems run more smoothly. I am releasing some of these bits of custom code in the form of plugins to help other bloggers.
Limiting Comment Length With a WordPress Plugin
Most of us welcome comments on our blog posts, but that doesn’t necessarily mean that we — or our readers — like to see comments reaching into thousands of words. Readers may be discouraged from commenting themselves (or reading comments at all) when they see very long entries left by others, and during times of high load, the significant performance overheads associated with retrieving and displaying long comments can slow even the speediest dedicated servers.
From the perspective of SEO (search engine optimization), very long comments also dilute the impact of the author’s original post by relegating it to a small proportion of the overall content available on the page.
The primary approach to limiting the total volume of comment material displayed on a page has long been to break up comments across several pages — either via a plugin like Keyvan Minoukadeh’s Paged Comments or now with the built-in paged comment feature introduced in WordPress 2.7.
This plugin provides one more tool by directly limiting the length of any one comment. A lightweight Javascript counter — just 5 lines of inline Javascript, with no gigantic external AJAX libraries to load — lets the user know how many characters they have left to complete their entry. Any additional text which might be inserted beyond the configured limit via cutting and pasting is automatically trimmed to length.
For users without Javascript, the counter degrades gracefully, providing a visual indication of the preferred (but unenforced) length limit, without the countdown feature.
For coders, the plugin provides additional configuration options via direct calls.
Installing Greg’s Comment Length Limiter Plugin
Installation works just like any other WordPress plugin: just unzip the plugin archive and upload it to /wp-content/plugins/ — be sure to upload the entire folder gregs-comment-length-limiter. Then you can activate the plugin via the WordPress ‘Plugins’ menu, and configure options via Settings -> Comment Length Limiter.
How to Use Greg’s Comment Length Limiter Plugin
With just a single line of code, most themes which support WordPress 2.7 will also support the comment length limit provided by this plugin. (Note that themes must include the wp_footer() call in order for this plugin — and many others out there — to work correctly.)
- Make sure your comment form has a name attribute of
commentform. (The default template includes an id with this value, but not a name attribute.) - Add the following function call within the textarea tag for your comment area, preferably wrapped in a conditional that tests whether the function exists:
<?php gcll_tweak_textarea(); ?>
For example, here is how the WordPress 2.7 default theme’s comment textarea looks after updating the tag to support Greg’s Comment Length Limiter plugin:
<p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4" <?php if (function_exists('gcll_tweak_textarea')) gcll_tweak_textarea(); ?>></textarea></p>
Optionally, if you would like to position the countdown box yourself, add the following function call wherever you would like the box to appear within your comment form, again preferably wrapped in a conditional that tests whether the function exists:
<?php gcll_show_limit_box_manually(); ?>
The plugin settings page allows you to specify whether you would like the plugin to place the countdown box automatically, or whether you would prefer to do that yourself. If you specify that the plugin should place the countdown box automatically, that setting will apply even if you also include manual placement code within your theme — in other words, the plugin is intelligent enough not to attempt to do it twice. So, if you’d like to compare your placement with the default placement, you can flip the manual placement setting on and off and view the results, without repeatedly adding and deleting the call from your theme.
Calling WordPress Plugin Functions Directly
For styling purposes, manual calls to display the countdown box, using <?php gcll_show_limit_box_manually(); ?>, can also take one parameter specifying your preferred class for the <span> which encloses the box: <?php gcll_show_limit_box_manually('mypreferredclass'); ?>.
The default <span> class is countdownbox.
Safe Wrapping of Plugin-Dependent Function Calls
I cover safe wrapping of plugin-dependent function calls on the information page for one of my other plugins: “Greg’s Threaded Comment Numbering Plugin for WordPress”.
Deactivating and Uninstalling this WordPress Plugin
You can deactivate Greg’s Comment Length Limiter plugin via the plugins administration page, and your preferences will be saved for the next time you enable it.
However, if you would like to remove the plugin completely, just disable it via the plugins administration page, then select it from the list of recently deactivated plugins and choose “Delete” from the admin menu. This will not only delete the plugin, but it will also run a special routine included with the plugin which will completely remove its preferences from the database.
Frequently Asked Questions About Greg’s Comment Length Limiter Plugin
- If my theme doesn’t include
wp_footer(), can I still use this plugin? - The plugin relies on
wp_footer()to incorporate its inline Javascript into the page, so without that call, the countdown box won’t function.
Revision History
I’ve moved the revision history to the README file distributed with the plugin.
Fine Print for this WordPress Plugin
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Get the Plugin!
You can download the plugin right here: Greg’s Comment Length Limiter Plugin.
Other articles by Dr Greg Mulhauser, Managing Editor
This article was last reviewed by Dr Greg Mulhauser, Managing Editor on Wednesday, 4th February 2009. Both comments and pings are currently closed.
The URL of this page is:
http://counsellingresource.com/features/2009/02/04/comment-length-limiter-plugin/
41 Responses (Including 13 Discussion Threads) to “Greg’s Comment Length Limiter Plugin for WordPress”
-
Neil Prestemon11
Well, it’s not working for me; I’m using a modified version of “Generic Design” template. The box appears, my limit of 1000 is in there, but there’s no response.
I inserted the code and I get the following printed INSIDE my comment box:
onkeydown=”gcllCounter(this)” onkeyup=”gcllCounter(this)”My comment form’s name is “comment” and so is the id. When I tried to change it to “commentform” – suddenly, it would no longer submit the post. The button would press and nothing.
So I guess my question is: is there somewhere else I need to change “comment” to “commentform” so that changing this name does not break my submission?
-
Neil Prestemon12
I see what I did wrong. There was an extra closing tag, and I deleted it, but that should have been my clue that I wanted to get rid of the closing tag from the <textarea parameters – I did that, and I added a name parameter to the form. That did the trick.
I couldn’t send you a url for the site yet, because it’s still in development, and not yet public. We haven’t assigned a public address to it yet; but this plugin feature is very handy – I’m demoing it to my customer so they can see if they want to use it.
-
13
Hi there! It worked fine with WP 2.8.4 and Arclite 1.5.4 theme. Yes, I had to modify theme’s comments.php. The only problem – in WP admin “Plugins” has a red circle with number “1″ in it righ after activation of the plugin. And plugin’s setting are not available – it only shows small “tools” icon
-
Hector14
I’ve used your plugin in my site…. work fine, but never display the counter diminishing the characters while I am writing.
I see that in your site the counter is diminishing in real time the “characters available”, What can i do for work this feature?
Thanks for your quick assistance.
-
15
Greg… sounds like a great plugin, and exactly what I need (I’ve got a couple of loyal readers who are wonderful, but are fond of 1000+ word comments. !!) But… I’m not a guy who’s comfortable with code, and can’t get the plugin to work.
I’m using Vladimir Prelovac’s Amazing Grace theme. I have no idea of how to find whether or not the comment form has the name attribute “commentform”. (I’ve looked through comment.php but can’t find it.) I inserted the code into the appropriate line, but it doesn’t seem to work.
aaaarrrggghhhh! I may need counseling after all of this! ;-) Can you help??
Thanks in advance…
Kevin
-
16
Greg,
Thanks for your response. Good news/bad news: I’ve gone back and tried several things… the plugin seems to work ok at present, except the countdown “character counter” is there, but doesn’t count down. (As I type this, your counter is functioning normally.)
I tried pasting a 900+ word document as a comment, and when I submitted it, the plugin truncated it, per the settings I’d opted for. So it works (I think), but the counter isn’t.
Any thoughts?
Thanks for your time and help!
Kevin
-
17
[...] last bit brings me to my blog-update related news. I added a new plugin tonight, “Greg’s Comment Length Limiter” which pretty much does exactly what it says. When I’m quickly perusing the spam folder [...]
-
18
I finally got it to work. If you know nothing at all about XHTML, you may struggle a bit. I found this article to be of help: http://is.gd/4wyxX



« Older Comments