Codeable info

How To Disable HTML Code In User Posted Comments

Posted on by in WordPress Tutorials

Possibly one of the worst features in WordPress, which subsequently also happens to be the best, is the fact that ANYONE can post comments on various blog posts and entries. This allows visitors and loyal readers to comment or share opinions specifically on a certain post.

The downside to ANYONE having access to posting comments is that various bots and advertising companies can blast ridiculous amounts of spam and gain free advertising through the use of integrated html tags. Luckily, the native Akismet WordPress plugin automatically filters spam and some of the more worthless comments.

But there is one thing that Akismet does not do, and that is successfully turn off HTML code in the comments section. This means that sometimes various comments can get through the Akismet filter which include outside links. There are other reasons however for turning off HTML code and HTML content in the comments section, such as disabling user made tables, text styling, and any type of editing that’s possible through the use of HTML code.

In order to successfully disable HTML code and content in the comments section of your WordPress enabled blog or site the “functions.php” active theme source file must be edited.┬áThe following code can be entered anywhere in the file ABOVE the end tags (it must not break existing code or commands however):

// This will occur when the comment is posted
function plc_comment_post( $incoming_comment ) {
// convert everything in a comment to display literally
$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
// the one exception is single quotes, which cannot be #039; because WordPress marks it as spam
$incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );
return( $incoming_comment );
}
// This will occur before a comment is displayed
function plc_comment_display( $comment_to_display ) {
// Put the single quotes back in
$comment_to_display = str_replace( ''', "'", $comment_to_display );
return $comment_to_display;

It’s that simple. After the code above has been implemented into the “functions.php” active theme source file HTML links, code and content will not display correctly in comments. It will display exactly as it appears, meaning in native HTML code and tag form. This will ultimately discourage all use of HTML content in user posted comments.

)
Codeable info

Comments (2)

Comment by bhobia says:

Hey thanks dear its really good information here. Thanks for it.

Comment by anastasyea says:

How To Disable HTML Code In User Posted Comments for Blogspot

Codeable info