Change Displayed Text

Last updated on Tuesday, May 31st, 2011

These instructions are intended for those who are proficient in creating & installing custom plugins. The relevant tutorials for creating & installing plugins can be found on wordpress.org. If this is beyond you, we do offer a competitively-priced plugin creation & installation service starting at £50 per plugin. Please contact us for further details.

Although it won’t be possible to change every bit of text that eShop uses, you will be able to change some without the need for a full translation (po/mo etc). Use the example plugin below to create your custom text-mangler plugin. The plugin is based on Peter Westwood’s PJW Translation Mangler 1.

Example

<?php
/*
 Plugin Name: eShop Text Mangle
 Plugin URI: http://quirm.net
 Description: Replacing eShop texts the plugin way. Based on PJW Translation Mangler by Peter Westwood http://blog.ftwr.co.uk/
 Author: Rich Pedley
 Version: 0.01
 Author URI: http://quirm.net/
*/

class eShop_Translation_Mangler {
 /*
* Filter the translation string before it is displayed.
*
 * @param $translation The current translation
 * @param $text The text being translated
 * @param $domain The domain for the translation
 * @return string The translated / filtered text.
 */
 function filter_gettext($translation, $text, $domain) {
   $translations = &get_translations_for_domain( 'eshop' );
   switch($text){
   //example of changing the default @ symbol in option @ price etc.
   case '%1$s @ %2$s%3$s':
     return $translations->translate( '%1$s : %2$s%3$s' );
     break;
  }
  return $translation;
 }
}
add_filter('gettext', array('eShop_Translation_Mangler', 'filter_gettext'), 10, 4);
?>

WordPress Theme Development

Top