SPECIAL NOTE FOR UPGRADERS:
- Remember to copy the text replacement array (
$text_to_replace) from your current text-replace.php before overwriting it with the latest version. You’ll need to transfer that information into the newer version. (And prior to all that, just go ahead and make a backup of the text-replace.php you are currently using prior to any upgrade of the plugin.
This plugin can be utilized to make shortcuts for frequently typed text, but keep these things in mind:
- Your best bet with defining shortcuts is to define something that would never otherwise appear in your text. For instance, bookend the shortcut with colons:
“:wp:” => “<a href=’http://wordpress.org’>WordPress</a>”,
“:aol:” => “<a href=’http://www.aol.com’>America Online, Inc.</a>”,
Otherwise, you risk proper but undesired replacements:
“Hi” => “Hello”,
Would have the effect of changing “His majesty” to “Hellos majesty”. One solution might be to instead have used ” Hi ” (with spaces).
- Do not use the backspace character, ‘\’, within the shortcut text.
- Be mindful of your use of quotes as you define replacement text. Escape embedded double-quotes.
- List the more specific matches early, to avoid stomping on another of your shortcuts. For example, if you have both “:p” and “:pout:”
as shortcuts, put “:pout:” first, otherwise, the “:p” will match against all the “:pout:” in your text.
- If you intend to use this plugin to handle smilies, you should disable WordPress’s default smilie handler.
- This plugin is set to filter the_content, the_excerpt, and if uncommented, comment_text.
- Movable Type users: This plugin could be used to do what MT’s <MTMacroDefine> did:
<MTMacroDefine name="cool" string="8)"> <img src="http://www.yoursite.com/images/cool.gif" alt="8)" /> </MTMacroDefine>
"8)" => "<img src='http://www.yoursite.com/images/cool.gif' alt='8)' />"
- SPECIAL CONSIDERATION: Be aware that the shortcut text that you use in your posts will be stored that way in the database (naturally). While calls to display the posts will see the filtered, text replaced version, anything that operates directly on the database will not see the expanded replacement text. So if you only ever referred to “America Online” as “:aol:” (where “:aol:” => “<a href=’http://www.aol.com’>America Online</a>”), visitors to your site will see the linked, expanded text due to the text replace, but a database search would never turn up a match for “America Online”.
- However, a benefit of the replacement text not being saved to the database and instead evaluated when the data is being loaded into a web page is that if the replacement text is modified, all pages making use of the shortcut will henceforth use the updated replacement text.
- Download the file text-replace.zip and unzip it into your wp-content/plugins/ directory.
Copy and paste the the code ( text-replace.phps ) into a file called text-replace.php, and put that file into your wp-content/plugins/ directory.
- Modify the array $text_to_replace in the plugin file to define the text replacements you’d like to have happen.
Note: If upgrading, you’ll want to copy this information from your previous version of this plugin.
- Activate the plugin from your WordPress admin ‘Plugins’ page.
- Use the shortcut in a post.
function c2c_text_replace( $text, $case_sensitive=false )
- $text : The text to processed for text replacement.
- $case_sensitive : Boolean value (either ‘true’ or ‘false’) to indicate if the search for shortcut text for possible replacement should be case sensitive or not; default is ‘false’
N/A — Just type your shortcut text into a post and when viewed on your site you should see the expanded text.
- WordPress Support Forums announcement of Text Replace
- 27 Mar 2005 : v1.0 released –
- Moved the array
$text_to_replaceoutside of the function and into global space
- Renamed function from
- Changed license from BSD-New to MIT
- Added installation instruction and notes to plugin file
- Verified that plugin works for WordPress v1.2+ and v1.5+
- Moved the array
- 23 Sep 2004 : v0.92 released — added optional argument
$case_sensitive(defaulted to ‘false’); changed from BSD-new to MIT license
- 09 Jul 2004 : v0.91 released, see comments
- 29 Jun 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.