Hide/Cut Post Text

Author:Scott Reilly
Version:2.0
Last update:10 April 2008
Compatibility:WP 2.0+, 2.1+, 2.2+, 2.3+ and 2.5+
Comments:go here
Download:[ zip ]
Description:

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 post text. Link text for cuts can be defined per-cut or omitted, and if used, cut links are uniquely anchored.

Extended Description

There are three types of tags introduced by this plugin.

cut

A cut tag encapsulates part of your post that you only want to display in full on the post’s permalink page. In place of the cut text on non-permalink pages (i.e. the blog’s front page, archive pages, etc), a link is shown that links to the cut section on the permalinks page. The text for the link is by default the value of the “Default link text” option for the plugin. You can define link text on a per-cut basis by specifying a cut="" value to the cut tag. Each cut link links to a unique anchor in the individual archive page.

  • <!--cut-->SOME TEXT HERE<!--/cut--->
  • <!--cut="Click here to read the gory details"--><!--/cut-->

hide

A hide tag encapsulates part of your post that you never want to display, or only ever want to display to logged-in users at or above a specified user_level. The default userlevel to view hidden text is defined as a plugin option that you can override. It can also be overridden on a per-hide tag basis by specifying the <userlevel="". A value of 11 effectively makes the text hidden from even the admin (except when editing the post). You can add a note to yourself as to why a section of text was hidden by optionally specifying a hide="" value.

  • <!--hide-->No one will be able to see this text on the blog.<!--/hide-->
  • <!--hide="This is a note just for admins" userlevel=10 -->SOME TEXT HERE<!--/hide-->

show

A show tag encapsulates part of your post that you only want to display in full on the post’s permalink page or on any page that isn’t the permalink page. The difference between a cut and a show is that the show does not show any evidence that there is text not being shown to the user. Either single or nonsingle must be specified.

  • Only show the cut text on the post’s permalink page : <!--show=single-->SOME TEXT HERE<!--/show-->
  • Only show the cut text on any non-permalink page : <!--show=nonsingle-->SOME TEXT HERE<!--/show-->

Also includes quicktag buttons (buttons added to the button toolbar above the post content field when writing a post) for the new tags to facilitate use (but can be disabled).

NOTE: No support is currently given to users of the visual editor (aka rich text editor, aka TinyMCE). No toolbar button is created for that editor, nor will the HTML comment style syntax of the tags play well with it.

Screenshots

  • A screenshot of the admin options page for the plugin, where you can define terms/phrases shortcuts and their related replacement text.
    screenshot 1

Installation

  1. Download the file hide-or-cut-text.zip and unzip it into your wp-content/plugins/ directory.
  2. Activate the plugin through the ‘Plugins’ admin menu in WordPress.
  3. Go to the Options → Hide/Cut (or in WP 2.5+: Settings → Hide/Cut) admin options page. Optionally customize the options.
  4. Use the cut, hide, and/or show syntax in posts to control the display (or lack thereof) for post text, as needed. (See examples.)

Examples

Here’s an (albeit contrived) example of the tags being used:


Let's say this is your post text.
<!--hide-->
This line will never be publically available.
<!--/hide-->
This line, however, will be visible.
<!-- hide = "I, as admin, only want to see this" userlevel=10 -->
Important stats about this post could go here and no one but admin would see this on the blog.
<!--/hide-->
Visible text again.
<!--cut-->
This line will only appear in the permalink page for this entry.  Instead of this text, non-permalink archive/main
pages will display the default linktext for cuts: "Read more..."
<!--/cut-->
This particular line will be visible on any non-permalink archive/main page.
<!--cut=Read the lengthy explanation...-->
Another section of cut text.  However, the linktext for this cut has just been defined to be "Read the
lengthy explanation..."
<!--/cut-->
Once again, this line is visible.  Each of the cuts made above will be automatically hyperlinked to the appropriate 
location in the permalink page for this post, to where that particular cut text begins.
<!--show=single-->
This text is part of a special kind of cut.  It will ONLY be visible from the PERMALINK page for this particular
post.  No indication that this text is part of the post will be evident anywhere else but the permalink page.
<!--/show-->
This line is always visible...
<!--show=nonsingle-->
Another special cut.  This text will ONLY be visible from NON-PERMALINK pages.  No indication that this text is part 
of the post will be evident on the permalink page.
<!--/show-->
And, as expected, this line is visible.

Frequently Asked Questions

  • Q: I’m using the visual editor and…?

    A: Stop right there. This plugin does not support use of the visual editor (aka rich text editor, aka TinyMCE) in ANY way. If you insist on using the visual editor, you won’t be able to use this plugin.


Release Log

  • 10 Apr 2008 : v2.0 — Release notes.
  • NOTE: Documentation and discussion about versions of this plugin earlier than v2.0 can be found here
  • 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 $single to is_single()
    • Prepended all functions with “c2c_”
    • Removed shortcut specifier in JavaScript calls to create QuickTag buttons
    • Changed license from BSD-New to MIT
    • Plugin is no longer WordPress 1.2 compatible
  • 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 & Disclaimer

Copyright © 2004-2008 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.


Acknowledgements

Thanks to all those who have contributed feedback and support!