Commenting your Code
When learning how to code in various languages, it often times helps to know the proper way to comment out certain items. If you don’t already know what it means to add a ‘comment’ to the code, just little notes. It can also be used to block something out, it’s stopping a certain piece of code from it being read by the browser, or whatever have you. Lets start, shall we?
HTML
<!-- HEADER START -->
Hints: It’s best to avoid using ‘ – ‘ (the dash) to keep things from getting confusing, and use spaces before/after the dashes.
CSS
/* clear div to fix errors */
Same concept for HTML, adding notes or blocking off code. Can be used inside or in-between elements.
PHP
/* WP functions (multiple lines)*/// I'm only going to use Category 4 here (1 line)
There are two kinds of comments you can use in PHP, the ‘/* */’ being for multiple lines of code, and ‘//’ for one line.
I hope that you learned something new! Enjoy!
Post your comments
-
Thanks to: Symmetric Web and Smashing Magazine.






3 Responses
[...] here to see the original: SoDevious.Net » Commenting your Code Share and [...]
I often need to toggle pieces of code. This is what I use to easily comment and uncomment:
/* */
This code can be quickly commented out by removing one character.
Now it is not commented out.
/* */
/* *
This code can be quickly uncommented by adding one character.
Now it is commented out.
/* */
So just by adding/removing the “/” (slash) character the code is commented/uncommented.
If it doesn’t make any sense, copy it and paste it somewhere where the syntax is highlighted. The comments will stand out better.
Another thing… if you have a large piece of code (PHP or JavaScript) that needs to be commented out but it already has /* this type of comments */ in it, you won’t be able to wrap it between /* and */ if you wanna turn it off.
Instead, you can wrap it in an if statement that’s always false:
if ( 1==2 ) {
this would be some code that won’t be executed
but we still have it here, in case we decide we do need it
/*
it can also have comments
*/
more code
}
Hey, yeah it’s really important, to comment your code, if you’re opening a project which you finished serveral months ago, and I you did not comment your code, It’s a mess to clean up the code and to find yourself back in the code
btw: I use mostly the /**/ commenting-variant