Some days ago I was asked from a WordPress blog owner how he could hide a post content placing a warning stating the content was not suitable for minors or sensible people, and displaying it only on a voluntary click on a link on the warning message.
Generally he asked if it was possible to place automatically that warning on a set of post without modify them all.
Luckly all those post was tagged as “warning” but it would be the same if they were on a specific category.
Using Header and Footer plugin, which was already installed, the solution was to surround the content of those posts with a DIV styled to be hidden and re-enable its visibility after the click.
So, in Header and Footer plugin, on Post Content tab, I added on “Before Content” configuration:
<?php if (has_tag('warning')) { ?> <div id="warning" style="display: none"> Warning, content not suitable to minors. <a href="#" onclick="document.getElementById('warning').style.display='block'; return false;"> Click here to see the content</a>. <? } ?>
and on “After Content” configuration I inserted the code to close the DIV:
<?php if (has_tag('warning')) { ?> </div> <? } ?>
That’s all, try it!
Many other controls can be done on a post, for example instad of looking if it has a tag, one can control if it is in a specific category with “in_category()” function. WordPress has a lot of those functions, just study the WordPress codex!