Hiding Info
When you want to hide information within the source code of web pages, there are several ways to do it. All have their drawbacks. One or more of the methods might be perfect for you.
I hide information a lot. Not for nefarious reasons, but for reminders in the future. Examples are why a table has a heavy border, the CSS styling before a change was made (in case I want to revert), and how certain calculations are done.
All those could be kept in a notes file. Still, information within the source code of the very web page where it applies is easier than remembering to update a notes file and then remembering where in the notes file the information exists. Immediately accessible notes speed things up.
With all that said, here are a few ways to hide information within the source code of web pages.
Hide With CSS
The CSS declaration display:none;
can be used to keep the content within a div or other content container from publishing on the web page.
Advantage: Works for any web page.
Drawback: Can be viewed with browsers' "page source" menu items.
Example:
<div style="display:none;"> [Information to hide] </div>
Hide With HTML
HTML comment tags can be used to keep stuff from publishing on the web page.
Advantage: Works for any web page.
Drawback: Can be viewed with browsers' "page source" menu items.
Example:
<!-- [Information to hide] -->
Hide With PHP Comment Tags
PHP comment tags can be used to totally remove comments before they reach the browser.
Advantage: Totally removes comments because PHP code is not sent to the browser.
Drawback: Works only on PHP web pages.
Example:
<?php /* [Information to hide] */ ?>
Hide With PHP if()
Colon Syntax
PHP if(false)
with colon syntax and endif
statements can be used to totally remove comments before they reach the browser. (This page describes colon syntax for control structures.)
Advantage: Totally removes comments because PHP code is not sent to the browser.
Drawback: Works only on PHP web pages.
Example:
<?php if(false): ?> [Information to hide] <?php endif; ?>
Those are a few ways to hide information within the source code of web pages.
There are other ways, like setting opacity to 0 or using transparent color for text that, in my opinion, are less workable for simply hiding text within the source code of a web page. So those aren't addressed.
Probably at least one of the methods presented above will work for you. I generally use one or another of the PHP methods.
(This content first appeared in Possibilities newsletter.)
Will Bontrager