What's WP
Find Everything Related to WordPress - Best Tutoriasl on WordPress!
How to Comment Out HTML Code in WordPress Effectively

How to Comment Out HTML Code in WordPress Effectively

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?

When to Comment out HTML CodeCommenting 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 -->

Comment out CSS, PHP & JavaScript

To make this tutorial more meaningful and useful, now we’d like to discuss CSS, PHP and JavaScript comments which are also widely used. CSS comments can be used to hide CSS styles as soon as you put them in a .css stylesheet; PHP comments are to be put into .php files; and JavaScript comments run in both HTML documents and .js files.

Actually, CSS, PHP and JavaScript comments use the same syntax, but there is indeed a small difference between a single-line comment and a multiple-line comment. For a single-line comment, it should be like this:

// <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.


Lucy has been a very experienced SEOer, technical writer, web developer, c# developer since 2002. Now she owns a startup in San Francisco, CA, focusing on running a couple of blogs to share knowledge and experience with global readers and deliver exceptional results to global sponsors by leveraging the power of Internet.