Wordpress plugins
Text Replace

Text Replace

Version : 3.7
Tested up to : 4.5.10
Number of download : 46057
Author : Scott Reilly
Average rating : 4 / 5 on 13 votes 13 votes, 4 avg.rating

Screenshots

Text Replace
Text Replace
Text Replace
Text Replace

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) 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”. 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 probably disable WordPress’s default smilie handler. This plugin is set to filter the_content, the_excerpt, widget_text, and optionally, get_comment_text and get_comment_excerpt. The filter ‘c2c_text_replace_filters’ can 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=”” :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 (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:” => “America Online“), 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 | Author Homepage Filters The plugin exposes five filters for hooking. Typically, the code to utilize these hooks would go inside your active theme’s functions.php file. Bear in mind that all of the features controlled by these filters are configurable via the plugin’s settings page. These filters are likely only of interest to advanced users able to code. c2c_text_replace_filters (filter) The ‘c2c_text_replace_filters’ hook allows you to customize what hooks get text replacement applied to them. Arguments: $hooks (array): Array of hooks that will be text replaced. Example: /** * Enable text replacement for post/page titles. * * @param array $filters Filters handled by the Text Replace plugin. * @return array */ function more_text_replacements( $filters ) { $filters[] = 'the_title'; // Here you could put in the name of any filter you want return $filters; } add_filter( 'c2c_text_replace_filters', 'more_text_replacements' ); c2c_text_replace_comments (filter) The ‘c2c_text_replace_comments’ hook allows you to customize or override the setting indicating if text replacement should be enabled in comments. Arguments: $state (bool): Either true or false indicating if text replacement is enabled for comments. This will be the value set via the plugin’s settings page. Example: // Prevent text replacement from ever being enabled. add_filter( 'c2c_text_replace_comments', '__return_false' ); c2c_text_replace (filter) The ‘c2c_text_replace’ hook allows you to customize or override the setting defining all of the text replacement shortcuts and their replacements. Arguments: $text_replacement_array (array): Array of text replacement shortcuts and their replacements. This will be the value set via the plugin’s settings page. Example: /** * Add dynamic shortcuts. * * @param array $replacements Array of replacement terms and their replacement text. * @return array */ function my_text_replacements( $replacements ) { // Add replacement $replacements[':matt:'] => 'Matt Mullenweg'; // Unset a replacement that we never want defined if ( isset( $replacements[':wp:'] ) ) unset( $replacements[':wp:'] ); // Important! return $replacements; } add_filter( 'c2c_text_replace', 'my_text_replacements' ); c2c_text_replace_comments (filter) The ‘c2c_text_replace_comments’ hook allows you to customize or override the setting indicating if text replacement should be enabled in comments. Arguments: $state (bool): Either true or false indicating if text replacement is enabled for comments. The default value will be the value set via the plugin’s settings page. Example: // Prevent text replacements from ever being enabled in comments. add_filter( 'c2c_text_replace_comments', '__return_false' ); c2c_text_replace_case_sensitive (filter) The ‘c2c_text_replace_case_sensitive’ hook allows you to customize or override the setting indicating if text replacement should be case sensitive. Arguments: $state (bool): Either true or false indicating if text replacement is case sensitive. This will be the value set via the plugin’s settings page. Example: // Prevent text replacement from ever being case sensitive. add_filter( 'c2c_text_replace_case_sensitive', '__return_false' ); c2c_text_replace_once (filter) The ‘c2c_text_replace_once’ hook allows you to 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. Arguments: $state (bool): Either true or false indicating if text replacement is to only occur once per term. The default value will be the value set via the plugin’s settings page. Example: // Only replace a term/shortcut once per post. add_filter( 'c2c_text_replace_once', '__return_true' );

Download now