Aug 092016

So there are some plugins out there to hide and show WordPress comments (notably the one named “Hide Show Comment“), but there are some things I didn’t like about it.

  1. They want you to pay for more options (I’m quite frugal).
  2. There is no option to hide the comment form – only the comments.

So here’s how you do it. We’ll be using jQuery (JavaScript) and inserting the code with a plugin.

  1. Install a plugin that lets you insert custom code.
    1. SEO Ultimate can do this under the “Code Inserter” section (use the “Before Item Content section).
    2. Insert Headers and Footers can do this (use the “Scripts in Header” section)
  2. Insert the script below.
<script type="text/javascript">
            // make the "leave a comment" text hide/show the comment form.

            // hide the comment form by default

            // make the text look like a link so the user knows it's clickable.
            // return false means the page will not reload.
            jQuery('.comment-reply-title').wrap("<a href="" onclick="return false;" >");

            // the reply button should always show the comment form
            jQuery('.comment-reply-link').wrap("<a href="" onclick="jQuery('.comment-form').show();" >");

            // the cancel reply link should always hide the comment form
            jQuery('.cancel-comment-reply-link').wrap("<a href="" onclick="jQuery('.comment-form').hide();" >");

That’s all you need really. The rest is just nitpicking. One issue is that the comment form is not hidden by default. If we simply add some CSS to fix it, then people who have JavaScript turned off will never see the comment form. So we want to hide the comment form by default only when JavaScript is supported.

    1. Add the following JavaScript to the header.
<script type="text/javascript">
document.documentElement.className = "js";
  1. Add the following custom CSS using a plugin or your theme (for example the plugin “Simple Custom CSS“).
/** hide the comment form only if JavaScript is enabled. */
.js .comment-form { display: none; }

The JavaScript-dependent CSS was taken from

Aug 152010

WP-SpamFree and Akismet are plugins for WordPress which are meant to stop spam comments. Unfortunately they both have their issues. To jump to the point of the matter – you may want to only use WP-SpamFree and not use Akismet at all.

My experience has been that Akismet has reportedly blocked a fair amount of spam, but that I have no way to confirm this. There hasn’t been any approval or review of the spam it’s blocked, just some “XXX spam messages blocked!” messages. While this is great and all, it got me to thinking – what if it’s blocking valid comments as well. After a little search I found that Akismet may actually work by using large blacklists of IP addresses and marking any message from the blacklisted IPs as spam.

That’s bad for a number of reasons. If some Comcast user starts spamming people and gets their IP on the blacklist, their IP may change the very next day so some new unrelated user will be banned instead. If a whole range of IPs is banned instead of just one, then a whole range of unrelated users will be banned instead of just the one spammer. Without any verification on what Akismet is calling “spam,” I can’t in good conscience just let it continue to block messages.

Configure WP-SpamFree

WP-SpamFree has two settings (“Blocked Comment Logging Mode” and “Log All Comments”) which allow all blocked comments to be logged. Unfortunately the default is that this setting automatically turns off after 7 days. To configure WP-SpamFree to keep the log for more than 7 days, do the following.

  1. Under “Plugins” click “Editor”
  2. Under “Select Plugin to Edit” choose “WP-SpamFree” (and click select)
  3. Search for the text “ResetIntervalHours” in the wp-spamfree.php which should now be open.
    1. This is where the time limit is set to 7 days
  4. Simply adjust the 7 to be whatever you like, like 28 for example, and click “Update File”

Won’t the log file become HUGE?

No, probably not. If you look down a bit further in the code there is another setting which tells WP-SpamFree to turn off logging once the file reaches a certain size (2mb is the default currently). So once the file reaches 2mb the logging will turn off automatically. Personally I believe these things should be options changeable via the menu.

 Posted by at 3:46 pm