•  

Comment Validation update plus fix

By Austin On March 16, 2009 Under Plugins, Tips & Tricks

On this site I use the Comment Validation plugin from Jörn Zaefferer.

You can find out more about this plugin at the WordPress directory.

This plugin is an amazing plugin, but the new version breaks W3C validation. Mostly due to typo’s and small oversights. Lets take a looks at the original comment-validation.php file in version 0.3.

function commentValidation() {

echo '
';

echo '';
echo '';
echo '';

}

add_action('wp_head', 'commentValidation');

Hey, where you able to tell what need to be fixed? Well lets take a closer look.

Corrections

On line 15 you’ll see we need to change the closing tag to fit the link attribute and not a script. Since there is not closing link, will end it with a forward slash, we also we need the type attribute.
From this:

echo '/wp-content/plugins/comment-validation/comment-validation.css">';

To this:

echo '/wp-content/plugins/comment-validation/comment-validation.css" type="text/css" />';

That was pretty simple.. So I am also going to add a few lines that will return the code to a new line, so that my final code looks a little cleaner, this is something you don’t have to do.

Here is my example:

echo '/wp-content/plugins/comment-validation/comment-validation.css" type="text/css" />';
echo "n";

The n will return a new line..

I also don’t need the code on every page so I have added in a conditional code of is_singular. You can view the final code below.

So here we see the final in total. Remember I’ve added a few lines that you may not want to add or use:

function commentValidation() {

if (is_singular()) {
echo '
';
echo "n";

echo '';
echo "n";
echo '';
echo "n";
echo '';
echo "nn";

} else { return; }

}

4 Comments Add yours

  1. Montana Flynn
    April 20, 2009
    9:00 pm

    Thanks, my theme does not work well with the plugin for some reason. Actually every plugin. Is it because I use jquery for the sidebar? Anyways thanks for the code I tweeted it!

    Montana Flynn´s last blog post..How To: Show future posts in wordpress

    • Austin
      April 21, 2009
      3:03 pm

      Your welcome.
      Looks like your theme loads in it’s own jQuery as apposed to using: wp_enqueue_script

  2. Montana Flynn
    April 21, 2009
    3:42 pm

    I thought wp_enqueue_script was for plugins not themes… is it that the plugin is trying to load jquery as well the problem?

    Montana Flynn´s last blog post..How To: Show future posts in wordpress

    • Austin
      April 21, 2009
      5:10 pm

      It can be used for both plugins and themes. It’s so that multiple jQuery scripts don’t get loaded in the same theme.