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 amount of 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 pieces of coding is something 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 to become inactive and not be considered as the primary source code, even if temporarily. The key benefit to commenting out lines 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 in understanding 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 for. 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 different when it comes to commenting out your code. If you would 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.

Get 20% off on the Best WordPress Themes & Plugins

Get 20% off on the Best WordPress Themes & Plugins

WordPress consists of different types of files, with the majorly used ones being the PHP, HTML, and CSS ones. 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, below is the code 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 as a code comment, which you can address to at a later point in time.

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

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

 -->

 

Commenting out code in CSS Files

Similar to the 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 given 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 options of code snippets to wrap your code around.

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

OR

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

 

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 WordPress community does not prefer commented code for their themes or plugins directory. So, if you are about to publish your code on 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, feel free to use the above lines of code snippets and organize your code better.

 

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.

No Comments

Post A Comment

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