How to Comment Out Code in WordPress for PHP, HTML and CSS

The mark of a good programmer or coder is the one who documents their code properly. Coding is one of those skills that demand a good background in documenting the code being written. Although documentation is not of the primary skills required for coding, it is a skill that differentiates the veteran coders from the novice ones.

When you step up from being a hobbyist programmer to developing programs for your clients, properly documenting your coding pieces is essential and not optional in those cases.

What Is Commenting Out the Code, and Why It Matters?

To comment out code means that you are rendering some parts of your code inactive and not considered the primary source code, even if temporarily. The key benefit to commenting outlines of your code while you’re at it is that it helps you to recollect what a particular line of code was meant for.

This helps you in keeping track of your progress while working on a project. It also helps you understand certain aspects of your code instead of getting lost in millions of lines of undocumented code. Commenting out code also helps your clients for whom you’ll be developing your code. Commenting out code is supposed to help your clients understand the millions of lines of code that you wrote for them, of which they couldn’t tell which part of the code does what.

Also, in WordPress, it would be handy to hide some aspects of your untested code into the website template by commenting out your HTML, CSS, or PHP code. Commenting out your code makes it easier for you to hide parts of your unfinished or untested code into your website template from the published parts of your code.

How to Comment out Code in WordPress for PHP, HTML, and CSS

While all major scripting languages allow for commenting out code, WordPress works a bit differently when commenting out your code. If you wish to comment out your code in WordPress for your PHP, HTML, or CSS files, below is the code you can use to do the same.

WordPress consists of different types of files, with the majorly used ones being PHP, HTML, and CSS. WordPress Codex is a great place to start your Essential WordPress training from. Below is the exact standard set of procedures that you must use to comment out code in your WordPress files.

Commenting out code in HTML Files

To comment out lines of code in the HTML files of your WordPress website, you will need to wrap your code around. Doing so will leave the piece of code out of the main lines of code and be considered a code comment, which you can address later in time. Use WordPress customization service to make changes to your WordPress website.

<!--
<div class="redblock">

This is some HTML in
the redblock class.
</div>

 -->

Commenting out code in CSS Files

Like commenting out of HTML code, you can also comment out your CSS code in the CSS files of your WordPress website. Use the below code snippet to wrap your CSS code around and leave out parts of your code from the main executing code.

/* .redblock {font-size: 80%; font-style: italic; color: red; } */

Commenting out code in PHP Files

Now that WordPress is a PHP-based Content Management System, you will come across PHP files while working on WordPress. Now to comment out PHP code in WordPress, below are the two code snippets to wrap your code around.

<?php // the_content(Continue Reading...); ?>

OR

<?php /* the_content(Continue Reading...); */ ?>

Similar can be done in other PHP development projects.

What to Do When Error Occurs After Playing With Code

Luckily, there is a solution to any errors that prevent you from accessing your website after playing with code. It can happen that sometimes you mess up the code and can’t get past the login screen or get the white screen of death.

I want to introduce you to a plugin that will help you solve any problems or errors that may arise, the WP Reset plugin.

WP Reset

WP Reset is the tool you want to have whenever you make any changes to your website, whether minor or major. In this instance, when you are altering your code, there is a possibility that it won’t turn out the way you hoped. In such situations, it’s recommended you use a plugin such as WP Reset.

One of the greatest options it provides is the Snapshots option, which allows you to take a snapshot of your website before making any changes. That way, if something goes south, you can return to its previous state. Aside from the Snapshots feature, WP Reset offers additional cleaning tools and reset options.

Plus, WP Reset comes equipped with Emergency Recovery Script, a tool like no other. Within the script, you are provided with numerous tools that cover all the problems you may encounter on your website. Whenever you can’t access your website, get an error message or encounter the white screen of death, you can whip out ERS and let it work its magic.

Conclusion

While commenting out, the code is mandatory in some situations when dealing with clients; it is an excellent way to leave out pieces of code that you would like to address at a later point in time. Commenting out code is one of the best practices recommended for programmers.

But one thing must be mentioned here regarding how the WordPress community does not prefer commented code for their themes or plugins directory. So, if you are about to publish your code on the WordPress directory, make sure to get rid of commented code before hitting that publish button. As for commenting out code in WordPress for your own code development purposes, please use the above lines of code snippets and organize your code better.

In case you encounter any issues or errors after working on your code, be sure to check out WP Reset and Emergency Recovery Script. Both tools are incredibly valuable and should be in your arsenal.

What do you think about commenting out code in WordPress for the PHP, HTML, or CSS files? Are you an advocate of using code commenting? Feel free to share your thoughts and comments below.

Editorial Staff
mail@85ideas.com

Editorial Staff at 85ideas is a team of WordPress experts led by Brian Harris. Here to share amazing tuts, guides and collections.

5 Comments
  • Adam Rees
    Posted at 16:29h, 23 August Reply

    Simple and understandable. Thanks for sharing.

  • Spike Thomas
    Posted at 01:24h, 07 January Reply

    Great article. I learned here how to comment inside the PHP code. Because I always used to get confused how can I do that within HTML and PHP in WordPress? Now I am clear here. Thank you, dear.

  • Joquim
    Posted at 08:39h, 28 April Reply

    This guide is very helpful because it’ll assist me in many ways as i’m a novice in web development but willing to be better. I have a quick question that I wonder if you could answer. I’ve set up Woocommerce because I might be selling things in the future but am not right now. WordPress still has the shopping cart icon on my home menu and I’m not sure how to get that off for now. Any thoughts?

  • Abhijit
    Posted at 02:56h, 14 June Reply

    Awesome info, thanks for solutions.

  • Raman
    Posted at 02:03h, 07 July Reply

    wow, great article. Because I always used to get confused about how can I do that within HTML and PHP in WordPress?

    Now I am clear here. Thank you, dear.

Post A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.