Hide (so no one, or only users above a certain userlevel, can see) or cut (so only viewable on post’s permalink page) portion(s) of a post’s text. Link text for cuts can be defined per-cut or omitted, and if used, cut links are uniquely anchored. Quicktag buttons for the new tags are automatically created (but can be disabled).
This plugin gets you four basic features (actual two plus a pair of worthwhile variations):
1.) Hide portion(s) of post text
Any text falling between <!–hide–> and <!–/hide–> will be hidden from visitors, with no indication any text was hidden. Why? Maybe you want to leave yourself a note that no one else (who doesn’t have the ability to edit your post) can ever see. Maybe you want to remove section(s) of a post without removing the post entirely, and you don’t want to lose the original text, or lose track of it by pasting the text elsewhere. I’ve used it to remove documentation for a deprecated plugin. You can include comments to yourself about the hide via <!–hide=PUT YOUR NOTES HERE–>. *NEW* You can also hide text for users below a given user level while showing the text for those at or above the user level: in this manner : <!–hide=»Only high level users should see this» userlevel=9–>Secret stuff here…<!–/hide–>.
2.) Cut portion(s) of post text
While there are various cut plugins already, this was a fallout of my needing the hide feature, and just as well, I like the way this works. Basically, sections of post text falling between <!–cut–> and <!–/cut–> will only be displayed on the post’s permalink page. In place of the cut text in non-single pages is a link (by default it says «Read more…»). Customize the cut link text like so <!–cut=Read what I just cut…–>. Each cut link links to a unique anchor in the individual archive page.
3.) Single/individual archive only
This is a variation of the previous feature. Any text falling between <!–show=single–> and <!–/single–> will only appear in the post’s permalink page, but unlike a typical cut, non-permalink pages will not in any way reflect that text had been cut. I use this on coffee2code.com for each of my plugin announcements; on the permalink page, at the top of the post, you’ll notice there is a navigation bar that links down into the different sections of the post, but on the front page you don’t see the navigation bar.
4.) Non-single pages only
Any text falling between <!–show=nonsingle–> and <!–/show–> will only be visible in non-single pages (any page that the post would appear alongside other posts… i.e. the main page, yearly archive, monthly archive, daily archive, etc). The permalink page for the post will not in any way reflect that text had been cut.
Note: Users who have installed v0.9 of this plugin may want to undo the manually edits to quicktags.js that created the
«cut» and «hide» buttons so that the preferred method for dynamic button creation implemented by this version can be used.
If not, no biggie.
Note: The <!–cut=none–> tag is being phased out in favor of <!–show=single–>
- Download the file hide-or-cut-text.zip and unzip it into your /wp-content/plugins/ directory.
Copy and paste the the code ( hide-or-cut-text.phps ) into a file called hide-or-cut-text.php, and put that file into your /wp-content/plugins/ directory. Please ensure you do not introduce any spaces or other characters before the <?php or after the ?>
- Optional: Change configuration options in the file to your liking
- In the arguments to function hide_or_cut_text(), $allowed_types is a space-separated list that can include ‘cut’, ‘hide’, and/or ‘show’ (to indicate which you wish to use); the default is ‘cut hide show’; you probably don’t need to change this because you could simply not make use of the tags in your post if you don’t want to
- In the arguments to function cut_link_handler(), change $default_linktext to be the string used for the link for cut text when no per-cut link text is defined
- If you don’t want ANY quicktags created for you in the Post Edit admin page, find and comment out the following line in the code (by putting two forward slashes before it, i.e. «//»):
If you don’t want one or two of the three buttons from being created, edit the array in the function add_cuthideshow_buttons() to remove the button(s).
- Activate the plugin from your WordPress admin ‘Plugins’ page.
function c2c_hide_or_cut_text ($text, $allowed_types='cut hide show')
- $text : The text to be parsed for hiding/cutting appropriately tagged areas (basically the post content)
- $allowed_types : a space-separated list of tags you want to allow to be parsed from your post content; can be ‘cut’, ‘hide’, and/or ‘show’; the default is ‘cut hide show’; you probably don’t need to change this because you could simply not make use of the tags in your post if you don’t want to
function c2c_cut_link_handler ($linktext, $default_linktext='Read more...')
A helper function called by hide_or_cut_text().
- $linktext : custom per-cut link text as parsed from original text
- $default_linktext : the string used for the link for cut text when no per-cut text is defined
See this post for an example of post text (as seen in the admin edit post page).
This post is the rendered example of the previous sample post text.
- 11 Apr 2005 : v1.2 —
- Fix so that userlevel= will be acknowledged even when no comment text is provided for a ‘hide’
- userlevel= argument can now optionally be double-quoted
- 28 Mar 2005 : v1.1 —
- Added the function
c2c_hide_handler()to support ability to define userlevel= attribute to hide tag; only users at or above the specified userlevel are shown the text
- Switch from using
- Prepended all functions with «c2c_»
- Changed license from BSD-New to MIT
- Plugin is no longer WordPress 1.2 compatible
- Added the function
- 17 Aug 2004 : v0.91 — Various fixes and new features:
- New tags: <!–show=single–> (replaces the soon-to-be-phased-out <!–cut=none–>) and <!–show=nonsingle–>
- Per-cut link text and ‘hide’ comments can be double-quoted: <!–cut = «Read what I cut…» –>
- Quicktag buttons (the buttons appearing over the text entry field when writing a post) are now automatically created for ‘cut’, ‘hide’, and ‘show’ by this plugin.
- The newline character has been removed from the output of the cut-link links to allow for inline cutting.
- The second argument to hide_or_cut_text(),
$types, was changed to
$allowed_types, which is now a space-separated list of the tags to allow.
- 25 Jul 2004 : v0.9 — Released to the public
Copyright (c) 2004-2005 by Scott Reilly (aka coffee2code)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the «Software»), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED «AS IS», WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.