sandywp / plugins / text-replace

Text Replace

4.4 out of 5 stars. 4.4 18 reviews

Replace text with other text. Handy for creating shortcuts to common, lengthy, or frequently changing text/HTML, or for smilies.

Launch a sandbox with this plugin → No signup.
Ready in seconds.

v4.0 3,000+ installs WP 4.9+

your-sandbox.sandywp.com/wp-admin
Text Replace running inside a SandyWP sandbox

What you get inside

1 screen
  • The admin options page for the plugin, where you define the terms/phrases/shortcuts and their related replacement text

About this plugin

This plugin allows you to easily define text or HTML that should be used in your posts in place of words or phrases that are actually present in the posts. This is a handy technique for creating shortcuts to common, lengthy, or frequently changing text/HTML, or for smilies.

Additional features of the plugin controlled both via settings and filters:

  • Text replacement can be enabled for comments (it isn’t by default)
  • Text replacement can be made case insensitive (it is case sensitive by default)
  • Text replacement can be limited to doing only one replacement per term, per post (by default, all occurrences of a term are replaced)
  • Text replacement can be handled early or late in WordPress’s text filtering process (it’s early by default)
  • Text replacement can be expanded to affect other filters

A few things to 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: => WordPress
    :aol: => America Online, Inc.

Otherwise, you risk proper but undesired replacements:

Hi => Hello

Would have the effect of changing “His majesty” to “Hellos majesty”.

  • If you intend to use this plugin to handle smilies, you should probably disable WordPress’s default smilie handler on the Writing Settings admin page.

  • This plugin is set to filter ‘the_content’, ‘the_excerpt’, ‘widget_text’, and optionally, ‘get_comment_text’ and ‘get_comment_excerpt’. Filters from popular plugins such as Advanced Custom Fields (ACF) and Elementor are also handled by default (see FAQ for specifics). The “More filters” setting can be used to specify additional filters that should be handled by the plugin. The filter ‘c2c_text_replace_filters’ can also be used to add or modify the list of filters affected.

  • Text inside of HTML tags (such as tag names and attributes) will not be matched. So, for example, you can’t expect the :mycss: shortcut to work in <a href="" style=":mycss:">text</a>

  • SPECIAL CONSIDERATION: Be aware that the shortcut text that you use in your posts will be stored that way in the database. 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.

Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage

Developer Documentation

Developer documentation can be found in DEVELOPER-DOCS.md. That documentation covers the numerous hooks provided by the plugin. Those hooks are listed below to provide an overview of what’s available.

  • c2c_text_replace_filters : Customize what hooks get text replacement applied to them.
  • c2c_text_replace_third_party_filters : Customize what third-party hooks get text replacement applied to them.
  • c2c_text_replace_filter_priority : Override the default priority for the ‘c2c_text_replace’ filter.
  • c2c_text_replace Customize or override the setting defining all of the text replacement shortcuts and their replacements.
  • c2c_text_replace_comments : Customize or override the setting indicating if text replacement should be enabled in comments.
  • c2c_text_replace_case_sensitive : Customize or override the setting indicating if text replacement should be case sensitive.
  • c2c_text_replace_once : Customize or override the setting indicating if text replacement should be limited to once per term per piece of text being processed regardless of how many times the term appears.

Questions

Does this plugin modify the post content before it gets saved to the database?

No. The plugin filters post content on-the-fly as it is being output or displayed. The data saved to the database is as you typed it.

Does this plugin modify post content that already exists in the database?

No. The plugin filters post content on-the-fly as it is being output or displayed. The actual data stored in the database, whether it be pre-existing or new, is never affected by this plugin.

Will this work for posts I wrote prior to installing this plugin?

Yes, if they include strings that you’ve now defined as shortcuts.

What post fields get handled by this plugin?

By default, the plugin filters the post content, post excerpt, widget text, and optionally comments and comment excerpts. You can use the “More filters” setting to specify additional filters to be processed for text replacement. You can also programmatically use the ‘c2c_text_replace_filters’ filter to modify the affected filters (see Developer Documentation section).

How can I get text replacements to apply for post titles (or something not text-replaced by default)?

The easiest way would be to add “the_title” (or some other filter’s name) as a line in the “More filters” setting. That setting allows any additional specified filters to be processed for text replacement.

You can also programmatically add to the list of filters that get text replacements. See the Developer Documentation section for an example.

Is the plugin case sensitive?

By default, yes. There is a setting you can change to make it case insensitive. Or you can use the ‘c2c_text_replace_case_sensitive’ filter (see Developer Documentation section).

I use :wp: all the time as a shortcut for WordPress, but when I search posts for the term “WordPress”, I don’t see posts where I used the shortcut; why not?

Rest assured search engines will see those posts since they only ever see the posts after the shortcuts have been replaced. However, WordPress’s search function searches the database directly, where only the shortcut exists, so WordPress doesn’t know about the replacement text you’ve defined.

Will all instances of a given term be replaced in a single post?

By default, yes. There is a setting you can change so that only the first occurrence of the term in the post gets replaced. Or if you are a coder, you can use the ‘c2c_text_replace_once’ filter (see Developer Documentation section).

4.4

18 reviews

  • 5 ★ 15
  • 4 ★ 0
  • 3 ★ 1
  • 2 ★ 0
  • 1 ★ 2

Ratings come from WordPress.org. SandyWP does not collect its own reviews.

sandywp / also on the shelf

Try another plugin

  • Disable Search

    4.7 · 30K+ installs

    Disable the built-in front-end search capabilities of WordPress.

  • Configure SMTP

    4.9 · 6K+ installs

    Configure SMTP mailing in WordPress, including support for sending email via SSL/TLS (such as Gmail).

  • One Click Close Comments

    4.9 · 5K+ installs

    Conveniently close or open comments for a post or page with one click from the admin listing of posts.

Spin up a real WordPress site in seconds.

Test plugins, build a demo, hand a client a link — then squash it and start again. No local setup, no Docker.