• Skip to content
  • Skip to primary sidebar
  • Skip to footer

Foliovision

Main navigation

  • Weblog
    • FV Player
    • WordPress
    • Video of the Week
    • Case Studies
    • Business
  • About
    • Testimonials
    • Meet the Team
    • We Support
    • Careers
    • Contact
    • Pricing
  • Products
  • Support
    • FV Player Docs
    • Pro Support
  • Login
  • Basket is empty

How to Comment Code in WordPress Templates

Commenting code is very important to running successful long term websites.

When you come back to code, six months or eighteen months later, you won’t have a clue most of the time how or why it got there. The extra half hour figuring it out (as a minimum) is not worth the two minutes it takes to comment it now.

HTML comments are easy enough.

<!-- this is an html comment -->

When commenting WordPress, I’ve often gotten away with this.

The disadvantage of this method is that the comments show up in every html page for everyone to see your messy code. Too many messy comments may give the Google bot heartburn as well. The less stress you put on their parser, the better for your top-ranked websites. Googlebot’s vulnerability to comment confusion/penalty is probably less of an issue now than it would have been a few years ago (2002 to 2005).

But today I had a batch of PHP which threw errors when enclosed in an HTML comment.

So I had to go looking for a more serious way to comment a WordPress theme template file. WordPress theme template files are PHP so I would have though PHP commenting would work.

When commenting PHP, the following should work

// at the start of a line should make the rest of the line a comment.

But in WordPress templates that doesn’t work.

Alternatively the code for multiline comments CSS is supposed to work in PHP as well

/* here is the comment spanning
multiple lines */

That doesn’t work either in WordPress template files.

So what does work?

This simple syntax:

<?php /*
comment
*/ ?>

You wrap both html and PHP in another PHP tag.

Here is a full scale example:

<?php /*

go wild in this section and write whatever you want and leave whatever messy code you want in here: neither Googlebot or your competitors will see what you are up to. but the notes and functions will be here waiting for you or your programmer when you want to come back and have another stab at what it is you are working on. in this case, archives by year.

    <?php for ($x = date ('Y'); $x >= 2004; $x--) $years[] = '<a href="/weblog/vancouverrealestatenews'.$x.'/">'.$x.'</a>';?>
<?php echo implode (' | ', $years)?>
   
            <?php if (have_posts()) : ?>
                <?php while (have_posts()) : the_post(); ?>

*/ ?>

If you go that that Vancouver real estate news page, you’ll find that none of the above shows up at all.

Commenting code in WordPress templates is simple once you get the hang of it.

Addendum

By force of necessity, I’ve become more proficient at commenting PHP.

To comment part of a section, you have to already be inside PHP tags. So you don’t need to open a new set.

// will get you there as a one line comment if you are in PHP tags and at the end of a line. Line wrap will apply. Just don't hit the return character.

/* Multiple line comments are also possible within PHP comments.
Hit return as many times as you want.
Wrap the comments in the slash-asterisk - asterisk-slash combo */

But all of the above is true if you are trying comment out the html sections of a PHP document. You have to wrap the html in a PHP tag. And if you are trying to build section dividers, you also have to use PHP comment wrappers.

Reader Interactions

Comments

  1. Norman 26 February 2008 at 9:13 am

    Thanks a lot for this information, that what i was looking for to do in my blog but, I didn’t know what was the term for it. Well now i know and thanks for the tips.

    Reply
  2. Chris 28 June 2008 at 5:30 pm

    Thanks this really helped out!

    Reply
  3. zwil 5 February 2013 at 12:22 am

    Thank you very much! U saved my day :)

    Reply
  4. Diego 8 November 2013 at 5:23 pm

    Thank you! This worked for me!

    Reply
  5. Shaadat Rahman 25 January 2017 at 10:09 am

    Thank For this information, that what i was looking for to do in my blog but, I didn’t know what was the term for it. Regards, Shaadat Rahman pixelll.com/

    Reply
  6. Phil Marsosudiro 2 April 2017 at 4:53 am

    Fantastic help — and so clearly written. Thank you! Ďakujem!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You can click here to Subscribe without commenting

Primary Sidebar

WordPress How To Guides

  1. StudioPress Tutorials
  2. WordPress Tutorial Videos for Foliovision Clients
  3. WordPress Plugins
  4. Shared.css Framework
  5. WordPress How To Guides
    1. How to Hack a WordPress Theme
    2. How to alter WordPress comment email
    3. How to reorder pages
    4. How to create your own filled-in extension
    5. Lost your password in WordPress?
    6. How to Comment Code in WordPress Templates
  6. WordPress Plugin Reviews

Footer

Our Plugins

  • FV WordPress Flowplayer
  • FV Thoughtful Comments
  • FV Simpler SEO
  • FV Antispam
  • FV Gravatar Cache
  • FV Testimonials

Free Tools

  • Pandoc Online
  • Article spinner
  • WordPress Password Finder
  • Delete LinkedIn Account
  • Responsive Design Calculator
Foliovision logo
All materials © 2025 Foliovision s.r.o. | Panská 12 - 81101 Bratislava - Slovakia | info@foliovision.com
  • This Site Uses Cookies
  • Privacy Policy
  • Terms of Service
  • Site Map
  • Contact
  • Tel. ‭+421 2/5292 0086‬

We are using cookies to give you the best experience on our website.

You can find out more about which cookies we are using or switch them off in .

Powered by  GDPR Cookie Compliance
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Necessary Cookies

Strictly Necessary Cookie allow you to log in and download your software or post to forums.

We use the WordPress login cookie and the session cookie.

If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.

Support Cookies

Foliovision.com uses self-hosted Rocket.chat and self-hosted Freescout support desk to provide support for FV Player users. These cookies allow our visitors to chat with us and/or submit support tickets.

We are delighted to recommend self-hosted Rocket.chat and especially Freescout to other privacy-conscious independent publishers who would prefer to self-host support.

Please enable Strictly Necessary Cookies first so that we can save your preferences!

3rd Party Cookies

This website uses Google Analytics and Statcounter to collect anonymous information such as the number of visitors to the site, and the most popular pages.

Keeping this cookie enabled helps us to improve our website.

We reluctantly use Google Analytics as it helps us to test FV Player against popular Google Analytics features. Feel free to turn off these cookies if they make you feel uncomfortable.

Statcounter is an independent Irish stats service which we have been using since the beginning of recorded time, sixteen years ago.

Please enable Strictly Necessary Cookies first so that we can save your preferences!