Using filter gettext
-
I’m not a programmer but I’d like to learn just one thing: to replace a certain text in a page with another one.
I saw somewhere the following(please see below) code, which should do the job (which I suppose should be added to theme functions.php)and I’d like to add corresponding code in the right template file.
My qustions:
1. Suppose the orginal text is ‘text1’ and the replaced is ‘text2’, what is the syntax of the calling function in the template file?
2. Suppose the page(which its text I want to modify) uses index.php, which itself imports header.php. Can I put the calling function in header.php?
Regards
I. Lesher
function my_text_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case ‘Related Products’ :
$translated_text = __( ‘Check out these related products’, ‘woocommerce’ );
break;
}
return $translated_text;
}
add_filter( ‘gettext’, ‘my_text_strings’, 20, 3 );
The topic ‘Using filter gettext’ is closed to new replies.