Top

Daily Tip: How to Comment Out Code in WordPress

May 21, 2011

Here is a basic tip for working with WordPress files. “Commenting out” code is a way making a section or block of code inactive. It can be handy, because there are times when you may want to temporarily comment code out but leave it in there so that you can use it later. It essentially hides the code until you remove the comment code.

Depending on what type of file you’re working in, there are different bits of code you’ll need to use. These examples are taken directly from the WordPress codex:

To comment out HTML:

<!-- <div class="redblock"><p>This is some HTML in
the redblock class.</p></div> -->

CSS file example:

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

Within PHP tags:

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

or

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

This is a very basic skill that you will want to have under your belt when working with WordPress files. For more information about commenting code, please refer to the WordPress codex.

Comments

Comment Tags: CSS | php | HTML | Comments

2 Responses to “Daily Tip: How to Comment Out Code in WordPress”

  1. Samuel Smith on May 23rd, 2011 7:41 am

    HA! I thought I might run into that problem. Let me try to rewrite a different example block:

    <!– –>

    That would be a loop to print variables in an unordered list, commenting out PHP and HTML, individually… unless of course this one doesn’t display either. In which case I’ll just give up and get back to work…

  2. Samuel Smith on May 23rd, 2011 7:38 am

    Additionally keep in mind that code may be mixed, and commenting for each “language” may be necessary.

    For example, a section of PHP that sets a variable,and then displays it in an H1 tag will need to contain comment marks for the PHP and the HTML, like so:

    <!– –>

    Simply putting /* block comments */ around the wrapping PHP tags won’t prevent those list items in HTML from being displayed.

    Now, code should ideally be written to reduce the chance of a situation like this (using “echo” or something of the like), but it *is* a fairly common occurrence.

    Comment Tags: Comments, CSS, HTML, php

Got something to say?

Bottom
Article Archive  |  This site is a historical archive of pressography.com, a WordPress plugin and theme blog that published between 2006 and 2012. It is preserved for reference and is not operated by, affiliated with, or endorsed by its original authors. Nothing here is for sale and no form on this site is active. If you are the original owner and would like this domain returned, please get in touch.