Custom text in theme through functions.php
Now, I know the standard of fixing custom text is usually done through editing the php of a child theme, but I want to become more proficient in using functions, which seems like a similar robust solution, is it not? I saw it recommended a few places at least.
I am using the Avada theme and I want to change a few bits here and there to my native language (a few bits missed by the current .po / .mo files).
I found this piece of code that I do sort of understand.
function tribe_custom_theme_text ( $translation, $text, $domain ) {
$custom_text = array(
'something %s' => 'something %s',
);
if( (strpos($domain, 'tribe-') === 0 || strpos($domain, 'the-events-') === 0 || strpos($domain, 'event-') === 0) && array_key_exists($translation, $custom_text) ) {
$translation = $custom_text[$translation];
}
return $translation;
}
add_filter('gettext', 'tribe_custom_theme_text', 20, 3);
But I have a few questions!
Firstly, is this the proper way of doing it (if not how)?
Secondly, if so; how do I go about identifying the text domains?
Posted Aug 25, 2017, 12:03 PM UTC
15