Last active
August 12, 2016 01:36
-
-
Save elimn/6129520508249de627913ad2ee012bb8 to your computer and use it in GitHub Desktop.
MT | Swap every instance of a word for another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * SWAP EVERY INSTANCE OF A WORD FOR ANOTHER | |
| * See the codex to learn more about WP text domains: | |
| * http://codex.wordpress.org/Translating_WordPress#Localization_Technology | |
| * Example Tribe domains: 'tribe-events-calendar', 'tribe-events-calendar-pro'... | |
| */ | |
| function tribe_str_replace ( $translation, $text, $domain ) { | |
| // Put your custom text here in a key => value pair | |
| // Example: 'Text you want to change' => 'This is what it will be changed to' | |
| // The text you want to change is the key, and it is case-sensitive | |
| // The text you want to change it to is the value | |
| // You can freely add or remove key => values, but make sure to separate them with a comma | |
| // The following example changes "tickets" to "seats" | |
| $custom_text = array( | |
| 'Ticket' => 'Seat', | |
| 'ticket' => 'seat', | |
| 'Tickets' => 'Seat', | |
| 'tickets' => 'seats', | |
| ); | |
| $tribe_domain_prefixes = array( | |
| 'tribe-', | |
| 'event-', | |
| 'the-events-', | |
| ); | |
| // Exit if this is not a tribe text domain | |
| $is_tribe_domain = false; | |
| foreach( $tribe_domain_prefixes as $prefix ) { | |
| if( 0 === strpos( $domain, $prefix ) ) { | |
| $is_tribe_domain = true; | |
| break; | |
| } | |
| } | |
| if( ! $is_tribe_domain ) return $translation; | |
| // Does a regex search replace for each pattern | |
| $translation = str_replace( | |
| array_keys( $custom_text ), | |
| $custom_text, | |
| $translation | |
| ); | |
| return $translation; | |
| } | |
| add_filter( 'gettext', 'tribe_str_replace', 20, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment