Comments: Managing Your Comment Length
Comments on a blog are a good thing however, lengthy comments can be a little overwhelming to other readers and experts argue that long comments may be detrimental to the Search Engine Optimization of your site.
One of the posts on the Wishlist Member Insider forum mentioned two plugins, one of which I really liked – Greg’s Comment Length Limiter.
This nifty little plugin will allow you to set the number of characters that can be used in a comment – and set a default action (moderate, stop it, spam it, do nothing). Niiiiice.
I thought I’d share how to insert it in your theme template so you can experience the goodness too.
I recorded a quick video on how I inserted it on this site and then provided the edits to mak below:
[flv:https://askcharlyleetham.box.net/shared/static/557q8qqfkt.flv https://askcharlyleetham.box.net/shared/static/ttf6hz93f8.png 480 320]
After installing the plugin using the built in WordPress installer, you need to update your comments.php file to ‘call’ the comment limiter function.
comments.php is located in your Theme Folder – so navigate to wp-admin -> Appearance -> Editor
On most WordPress themes, the comments.php file looks like the one I’ve pasted below however, a custom theme may move the comments form to a custom function and you’ll have to locate the form within your theme files.
<?php
/**
* @package WordPress
* @subpackage Default_Theme
*/
// Do not delete these lines
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
die ('Please do not load this page directly. Thanks!');
if ( post_password_required() ) { ?>
<p><?php _e('This post is password protected. Enter the password to view comments.',woothemes); ?></p>
<?php
return;
}
?>
<!– You can start editing here. –>
<?php if ( have_comments() ) : ?>
<h1 id="comments"><?php comments_number(__('No Responses',woothemes), __('One Response', '% Responses',woothemes) );?> <?php _e('to',woothemes); ?> “<?php the_title(); ?>”</h1>
<div>
<div><?php previous_comments_link() ?></div>
<div><?php next_comments_link() ?></div>
</div>
<ul id="commentlist">
<?php wp_list_comments( 'callback=mywebblog_comments' ); ?>
</ul>
<div>
<div><?php previous_comments_link() ?></div>
<div><?php next_comments_link() ?></div>
</div>
<?php else : // this is displayed if there are no comments so far ?>
<?php if ('open' == $post->comment_status) : ?>
<!– If comments are open, but there are no comments. –>
<?php else : // comments are closed ?>
<!– If comments are closed. –>
<p><?php _e('Comments are closed.',woothemes); ?></p>
<?php endif; ?>
<?php endif; ?>
<?php if ('open' == $post->comment_status) : ?>
<div id="respond">
<h1><?php comment_form_title( __('Leave a Reply',woothemes), __('Leave a Reply to %s',woothemes) ); ?></h1>
<div>
<small><?php cancel_comment_reply_link(); ?></small>
</div>
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p><?php _e('You must be',woothemes); ?> <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>"><?php _e('logged in',woothemes); ?></a> <?php _e('to post a comment',woothemes); ?>.</p>
<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform" name="commentform">
<?php if ( $user_ID ) : ?>
<p><?php _e('Logged in as',woothemes); ?> <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="<?php _e('Log out of this account',woothemes); ?>"><?php _e('Log out',woothemes); ?> »</a></p>
<?php else : ?>
<p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="author"><small><?php _e('Name',woothemes); ?> <?php if ($req) echo __('(required)',woothemes); ?></small></label></p>
<p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> />
<label for="email"><small><?php _e('Mail (will not be published)',woothemes); ?> <?php if ($req) echo __('(required)',woothemes); ?></small></label></p>
<p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" />
<label for="url"><small><?php _e('Website',woothemes); ?></small></label></p>
<?php endif; ?>
<!–<p><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>–>
<p><textarea name="comment" id="comment" cols="" rows="10" tabindex="4" <?php if (function_exists('gcll_tweak_textarea')) gcll_tweak_textarea(); ?>></textarea></p>
<p><input name="submit" type="submit" id="submit" tabindex="5" value="<?php _e('Submit Comment',woothemes); ?>" />
<?php comment_id_fields(); ?>
</p>
<?php do_action('comment_form', $post->ID); ?>
</form>
<?php endif; // If registration required and not logged in ?>
</div>
<?php endif; // if you delete this the sky will fall on your head ?>
Lot’s of code right? To call the comment limiting function, you’re looking for two lines only and you’re likely to find them near the bottom of the code. Simply use the Find function (ctrl F) to search for “<textarea” and you should be right! The code you’re looking for is:
<p><textarea name="comment" id="comment" cols="" rows="10" tabindex="4"></textarea></p>
It may differ a little to my comments area, but you need to identify the TEXTAREA with the name attribute comment.
Add the following to the text area tag:
<?php
if (function_exists('gcll_tweak_textarea')) gcll_tweak_textarea();
?>
It should look like this when you’re done:
<p><textarea name="comment" id="comment" cols="" rows="10" tabindex="4" <?php if (function_exists('gcll_tweak_textarea')) gcll_tweak_textarea(); ?>></textarea></p>
ONE LAST THING
When I implemented this on The WP Warrior, the character count down box appeared but it didn’t ‘count down’! I found that I had to make one more change to my comments.php file (so check it now while you’re making the changes)
Locate the line that looks like:
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
You may notice that this line does not include the NAME attribute. Greg’s Comment Length Limiter requires a name attribute.
Modify the line above to look like:
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform" name="commentform">
The name must be commentform
Be sure to update the settings of the Plugin under wp-admin -> Settings ->Comment Length Limiter – and you’re ready to go!
A parting note – you can place the count down box ‘elsewhere’ on your comment form, the full instructions are included in the settings window.
Greg has done a fantastic job with this plug-in – highly recommend it!
