Frequently I need to change specific bits of text within Wordpress plugins, usually buttons and usually set within the plugin files as strings.
Sometimes an overide within my child theme does the trick but in most cases seems like overkill to change one or two words. I've had some success using the 'gettext' hook, but it has been suggested this is bad practice as I'm 'pushing content through the eye of a needle'.
In the example below I'm able to change the text for two buttons specifically within the Memberpress plugin. It seems to work okay but is there a better way of doing this?
function mepr_account_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Update' :
$translated_text = __( 'Update Card', 'memberpress' );
break;
case 'Cancel' :
$translated_text = __( 'Cancel Subscription', 'memberpress' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'mepr_account_strings', 20, 3 );