PHPMatters Help You Better Hosting Your PHP-based Sites
How to Remove HTML Tags in WordPress Comment Section

How to Remove HTML Tags in WordPress Comment Section

Nowadays, internet is flooded with answers to queries related to technical issues, such as removing HTML tags from the comment section in WordPress, and you can find numerous answers on this issue. While some answers found in authentic websites and blogs might help, most of the solutions posted are by amateurs and do little in helping people successfully remove HTML tags from WordPress comment section. In this article, a detailed and professional tutorial can be provided to help you in achieving this goal, without taking help from some software engineers or complicated online resources.

Why Bloggers Prefer Removing HTML Tags from Comments?

Bloggers are very curious in respect of their blog quality. They intend to use high quality content for the readers through which they are able to create audience engagement on their page. This in return allows the blog owner to gain a market reputation and valuable search engine page rank. However, there may be an instance that some certain low ranked websites look forward to generating a backlink through a HTML tag of their own website. This is usually done by placing the HTML tag in the comment section.

HTML tag in Comment

The impact of this action proves to be beneficial for the person placing the HTML tag, because it gives his website a high quality backlink. Contrarily, from the perspective of a blogger, it harms his page because his readers may click on the presented tags and get redirected to some other websites that are of low quality. Therefore, the prevailing state of affairs turns hostile for the blogger and leaves him with no other option than to eliminate the existing HTML tags.

Removing the HTML tags from the blog not only preserves the standard of your blog, but also helps you avoid spam comment. The presence of automated bots often acts as a culprit in dissolving the reputation of a blog through random link placement in the comment section. It can be easily avoided if the placements of HTML tags are disabled in the comment section.

Ways to Remove Tags from Comments

Given here is an exhaustive tutorial with an easy to understand procedure for removing HTML tags from the comments section of WordPress. Three major ways have been identified here, all of which can be done easily.

Style.css (CSS File)

Choose WordPress’s theme folder for which you want to remove the HTML tags. Find the style.css file kept under the folder selected by you. A special code needs to be entered at the file’s end, which is:

remove tag in css file

After setting the display value as none for tags through the above code, upon execution, you can find the comment section free of HTML tags.

Comment.php (PHP File)

You can also remove the HTML tag through an alternative method. Here, you have to reframe some of the code lines specified in the comment.php file. First, you have to locate the comment.php file from the theme folder selected from your WordPress. After opening the code, you can see a specific coding line as mentioned in the following.

comment form php code

Changes need to be made in the code mentioned above. For this, you just need to replace the present code into another code mentioned in below.

comment array php code

Once the initial code is replaced with the above one, upon execution, the comments section of your WordPress can be free of HTML tags.

Function.php (PHP File)

Another alternative for removing HTML tags is by using a function.php file. This file is common in every theme of WordPress folders and defines multiple themes that are featured in this file. Therefore, the HTML tag lists as well as similar attributes of the comments section can easily be customized through this procedure. This also means that the you are able to demonstrate selected tags accordingly as well as to remove unwanted and unnecessary tags.

When you visit the code, you can see a function titled as jaya-customized-allowedhtmltags (), containing a global variable titled as $allowedtags. Now, the attributes and HTML tag arrays that are unwanted and unnecessary in the comments section can be designated as $unwanted variable.

remove tag in php file

In order to unset the global variable, function unset () can be implemented. Users need to just write the code after the file of function.php has ended. After the execution of “function.php” process, you can see that only the italic tag and anchor tag can be found in the comment section, and the unwanted HTML tag has been removed. Apart from the above, if you want to increase the number of tags or to add some specific tags in the comments section, you can easily transform the section through “comment.php”.

In summary, the above three methods are the best available and easily applicable ways for removing HTML tags from WordPress comments area.