Replace text with other text. Handy for creating shortcuts to common, lengthy, or frequently changing text/HTML, or for smilies.
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:
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 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./wp-content/plugins/
).Settings
-> Text Replace
admin options page and customize the options (notably to define the shortcuts and their replacements)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.
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.
Yes, if they include strings that you’ve now defined as shortcuts.
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).
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.
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).
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.
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).
Yes. While this plugin is compatible with many other plugins that modify post and widget text, this plugin has explicit built-in support for Advanced Custom Fields and Elementor, which provide additional content areas. See documentation on the hook ‘c2c_text_replace_third_party_filters’ for a complete list of default supported third-party filters and how to enable compatibility with other plugins and themes.
If you know the name of the filter provided by a plugin, you can add it to the “More filters” setting to have its value processed for text replacement.
Yes.
Highlights:
This feature release adds a new setting to allow for user-specified filters to be processed, updates the plugin framework significantly, improves the plugin settings page, extracts developer docs from readme into new DEVELOPER-DOCS.md, restructures unit test files, notes compatibility through WP 5.7, and more.
Details:
get_default_filters()
to return the default core and/or third-party filters processed by the plugin'admin_enqueue_scripts'
action instead of during 'init'
is_plugin_admin_page()
in help_tabs()
instead of reproducing its functionalityis_plugin_admin_page()
is used before 'admin_init'
action is firedis_plugin_admin_page()
to use get_current_screen()
when availablestyle
tagc2c_{PluginName}_Plugin_051
to c2c_Plugin_060
get_c2c_string()
as a getter for translated stringsget_c2c_string()
whitelist_options()
to allowed_options()
add_allowed_options()
instead of deprecated add_option_whitelist()
for WP 5.5+allowed_options
filter instead of deprecated whitelist_options
for WP 5.5+is_wp_version_cmp()
and get_c2c_string()
)is_wp_version_cmp()
as a utility to compare current WP version against a given WP versioncontextual_help()
to be easier to read, and correct function docblocksnumber_format_i18n()
to format integer value within input fieldreadme_url()
to refer to plugin’s readme.txt on plugins.svn.wordpress.orgtests/phpunit/
to house all files related to PHP unit testingbin/
to tests/bin/
tests/bootstrap.php
into tests/phpunit/
tests/
to tests/phpunit/tests/
phpunit.xml
to phpunit.xml.dist
per best practicesHighlights:
This minor release updates a bunch of documentation, updates a few URLs to be HTTPS, improves unit testing, and notes compatibility through WP 5.4+.
Details:
options_page_description()
tearDown()
reset_options()
callHighlights:
This feature release adds support for Advanced Custom Fields and Elementor, adds a new setting that can allow the plugin to run later to avoid potential conflicts with other plugins, adds a number of filters, updates compatibility to be WP 4.9-5.3+, and more.
Details:
c2c_text_replace_third_party_filters
for filtering third party filtersc2c_text_replace_filter_priority
for filtering hook priority for text replacement handlerreplace_once
value to ensure a valid value is used as arg for preg_replace()
plugins_loaded
action instead of on loadprintf()
rather than using string concatenationadd_settings_field()
to be an arraylabel
instead of p
label
for help text for checkboxes, otherwise use p
textarea
displays as a block to prevent orphaning of subsequent help textcapture_filter_value()
as a method for capturing default values provided for a filterget_filter_names()
as a helper method for getting the default and third-party filter namesunhook_default_filters()
as a helper method to unhook plugin’s default filters hooked to text_replace()
test_does_not_replace_within_markup_attributes()
test_does_not_replace_within_markup_attributes()
to test_does_not_replace_within_markup_attributes_but_does_between_tags()
Full changelog is available in CHANGELOG.md.