Created
January 17, 2013 15:04
-
-
Save benhuson/4556545 to your computer and use it in GitHub Desktop.
How to filter translated text in WordPress
This example shows how to filter the 'This product has sold out.' text in the WP e-Commerce plugin.
If the translation domain is 'wpsc' it will replace the text with 'This product is no longer available.'.
This file contains 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 | |
/** | |
* This example shows how to filter the 'This product has sold out.' text. | |
* If the translation domain is 'wpsc' it will replace the text with 'This product is no longer available.'. | |
*/ | |
add_filter( 'gettext', 'my_gettext_filter' ); | |
function my_gettext_filter( $translated_text, $text, $domain ) { | |
if ( 'wpsc' == $domain ) { | |
switch ( $text ) { | |
case 'This product has sold out.' : | |
$translated_text = __( 'This product is no longer available.', 'my_domain' ); | |
break; | |
} | |
} | |
return $translated_text; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment