How to Comment Out PHP Code
A number of themes are coming in with WP tags like the calendar tag included in the theme, but commented out (I assume so it’s easy for someone to activate the feature). Unfortunately, many of the well intentioned theme authors are wrapping the entire PHP block with an HTML comment like this:
<!-- <php get_calendar(); ?> -->
Instead of commenting out the PHP code like this:
<php // get_calendar(); ?>
or this:
<php /* get_calendar(); */ ?>
If you add HTML comments around the PHP block, it hides the resulting HTML from the page but the PHP is still executed. In the case of the calendar, the PHP code does database queries and other things that take time to process. If the calendar isn’t going to be displayed anyway, there is no point in executing this code.
I’ve fixed this when I’ve caught it in themes that have been submitted so far, hopefully future themes will avoid this problem entirely.
UPDATE: Kubrick includes the following code that shows up in almost every theme that comes in:
<!--<p><small><strong>XHTML:</strong> You can use these tags: <?php echo allowed_tags(); ?></small></p>-->
If you don’t want to use that code - please remove it, don’t just leave it in there.
March 6th, 2005 at 12:25 pm
If most Wordpress theme designers use dreamweaver or other coding tools that allow a convenient way to comment out a selection of code with the click of a button like this (Dreamweaver) :
<!--<div align="center">
<?php get_calendar(); ?>
</div>
-->
Obviously, it will hide your HTML code, the tag. Further, add the php comment as Alex pointed out:
<!--<div align="center">
<?php // get_calendar(); ?>
</div>
-->
That way, you get to use you favorite comment buttons and Alex gets to save precious time cleaning our code.I know I stated obvious things, but sometimes we ignore the obvious.
March 8th, 2005 at 9:34 am
Oooooooo, I was getting it wrong in my theme work. Ooops! Thanks for this man.
March 9th, 2005 at 12:25 pm
One can also use an intelligent Web Development Environment like Quanta Plus which will comment out your PHP or markup depending on where you are highlighting or where the cursor is. For HTML is uses HTML-style comments, if the cursor is on a line of PHP then it uses //, if you highlight a chunk of PHP then it uses /* */. It is pretty darn nifty.
March 9th, 2005 at 12:37 pm
Sure, but it’s still the job of the designer/developer to get the code right. Tools are just tools.