coffee2code.com/wp-plugins/text-replace
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>
Now becomes:
"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.
-OR-
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_replace
outside of the function and into global space - Renamed function from
text_replace()
toc2c_text_replace()
- 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.
68 replies on “Plugin: Text Replace”
Any idea if text-replace can work with feedwordpress plugin? The text-replace plugin works great for ‘normal’ posts however it does not affect posts created by feedwordpress from a syndicated feed.
[…] A volte i cambiamenti che un autore applica al suo blog non sono visibili ‘in superficie’, soprattutto quando si tratta di migliorie funzionali al meccanismo di editing e pubblicazione. E’ il caso del nuovo plug-in che sto per adottare nella preparazione di questo blog: si chiama ‘Text replace‘ ed e’ l’equivalente di quelle che in gergo informatico vengono chiamate ‘macro’, ovvero sistemi per automatizzare determinate operazioni. Anzi, piu’ precisamente somiglia moltissimo al meccanismo di sostituzione automatica del testo che troviamo in Microsoft Word, e che aiuta a digitare parole o frasi di uso frequente associandole a una breve sequenza di caratteri, che una volta digitati sono automaticamente ‘tradotti’ nella parola o frase scelta. Nel caso del mio blog, visto che ancora adesso mi ritrovo quasi sempre a digitare carattere per carattere i tag HTML che aprono una pagina linkata in una nuova finestra oppure quelli che definiscono l’allineamento delle immagini rispetto al testo, credo che l’adozione di questo plug-in si rivelera’ una mano santa, come si suol dire. L’autore di Text Replace ha creato anche un plug-in piu’ evoluto, che si chiama Dynamic Text Replace e puo’ essere utilizzato, per esempio, per inserire automaticamente dei link che possono avere parametri diversi, come una ricerca di Google o un riferimento a un libro su Amazon. Inoltre, dello stesso autore, vi segnalo l’interessante Random File, che come dice il nome permette di inserire un file a caso scelto da una cartella sul server, per esempio per cambiare un’immagine all’interno dell’intestazione (come nel template Random Image). Un plug-in simile a questo e’ Random Witty Text, che come si capisce dal nome e’ specifico per l’inserimento di una porzione di testo prelevata a caso da un file, per esempio una citazione famosa o una barzelletta. Se volete approfondire l’argomento plug-in, ho inserito contestualmente a questo post anche qualche nuovo link nella sezione Blog World qui a fianco. Ah, ovviamente il titolo di questo post si riferiva al sito Cofee2Code, se c’e’ ancora qualcuno che si sta chiedendo cosa c’entra il caffe’ in tutto questo (a parte che si tratta della mia ‘droga’ quotidiana). […]
Hi,
Been using your plugin for long, it is great. I might have just found a little bug: it will replace text in javascript embedded in a post.
Im trying to use this to link to an affiliate code by replacing a specific word with a link such as this:
Any idea why this type of link isnt working?
I have the run-php and exec-php plugins installed and, the links work fine when manually added to a post just not when using text-replace 🙁
Any help you could offer would really be appreciated 🙂
Hmm.. the code didnt show up even though i put it in tags?
Trying to post the code again.
[…] Text Replace – Use shortcuts instead of often enter texts (in posts). […]
I’m also having trouble making text-replace work with Feedwordpress. Any suggestions? Thanks in advance!
im trying to change source code so links will automatically bypassed trough my tradescript, but when i have this:
" "
it just wont work, it wont be replaced...
anybody could help me out? Thanks in advance.
code is:
“ “/cgi-bin/at3/out.cgi?trade=”,
[…] Text replace plugin for WP (tags: wordpress plugins) […]
If we have installed php-exec plugin we can also use system strings-replacer for replacing string in post 🙂
[…] pour les liens visités, doré pour le hover. Le plugin très simple, très con et très utile Text Replace me d’avoir des smilies gtalk style 🙂 […]
Scott, you say in two sequential tips:
* Do not use the backspace character, ‘\’, within the shortcut text.
* Escape embedded double-quotes.
How do I escape embedded double-quotes?
Thanks
I’ve explained my dilemma further here, wordpress.org/support/topic/119893 .
[…] ***re is no actual Redacter plugin, it is just *** excellent Text Replace plugin with some really ***mmon text fragments in *** match list, but fun […]
is this working in 2.2 or 2.3? I cant get it to do anything.