Commenting out an HTML code, which means to make an HTML code inactive, is in demand in some cases. If you comment out some lines of code, you are making them temporarily hidden and not shown in web browsers. But they are still there in WordPress, so that you can make them active later by removing the comment lines. Therefore, commenting out code is actually to restore it for future use.
Commenting out code is quite easy as soon as you insert some comment codes. This post will discuss the comment codes, but firstly, we would like to make some explanations to when you should “hide” HTML codes.
When to Comment out HTML Code?
Commenting out codes is not a necessary feature, but there are indeed some times when it is useful. For example, if you are in one of the following situations, you may need to consider hiding some codes from your content.
- You need to test some lines of HTML code like plugin tags but do not want to show them.
- You need a line of code working as notes to record or explain what has been done for future reference.
- You are in the process of diagnosing website problems and may want to revert some code back in some steps.
- You want to hide a portion of a page or post that is going to be used later.
How to Comment out HTML Code?
There is an HTML comment designed to comment out code in an HTML coded document. The comment is a string of code widely used by developers to provide information about the code. Inserting it allows you to hide code, and on the contrary, removing it will activate the hidden code. See the comment as below:
<!-- This is the HTML code to be commented out -->
// <code to be commented out>
For a multiple-line comment, there is a different way shown as below.
/* <Code to be commented out> <Another line of code to be commented out> <More code to be commented out>; */
For PHP, the comments should be between <?php and ?> code.
As a conclusion, commenting out code is a very simple skill that you can use to master WordPress files. However, the fact is that comments are less popular with the rising of some web authoring programs. So when you use a comment, take more practices and make it as simple and meaningful as possible to prevent potential problems.