How do I change the words "posted by" and "on" that show on top of each WP post, to my own language?
For example I want to change this:
Posted by محمد on 6 نوفمبر 2018, 12:22 م
to:
كتبه محمد في 6 نوفمبر 2018, 12:22 م
I'm using a custom functions plugin, so I can add the code that you provide.
How do I change the words "posted by" and "on" that show on top of each WP post, to my own language?
For example I want to change this:
Posted by محمد on 6 نوفمبر 2018, 12:22 م
to:
كتبه محمد في 6 نوفمبر 2018, 12:22 م
I'm using a custom functions plugin, so I can add the code that you provide.
Share Improve this question asked Nov 14, 2018 at 11:10 MuhammadMuhammad 611 gold badge1 silver badge5 bronze badges 1- This likely isn't something that can be changed in a custom functions plugin. It would be part of your theme's templates. – Jacob Peattie Commented Nov 14, 2018 at 11:12
1 Answer
Reset to default 1This can MOST LIKELY be done with the get_text filter. Here's an example (and then some caveats):
function my_theme_text_switcher( $translations, $text, $domain ) {
if ( $domain == 'my-theme' && $text == 'posted by' ) {
$translations = __( 'YOUR TEXT HERE', 'my-theme' );
}
if ( $domain == 'my-theme' && $translations == 'on' ) {
$translations = __( 'YOUR TEXT HERE', 'my-theme' );
}
return $translations; }
add_filter( 'gettext', 'my_theme_text_switcher', 10, 3 );
Now the caveats:
- Go to your theme and find the single.php template and look for the post markup where those words are output. IF they are output with proper internationalization then the snippet above will work. It'll look something like this:
__('post by', 'my-theme');
- If that is there correctly, look for that second part the "my-theme" part. That is your theme's translation domain. You need to use that in the function correctly.
- IF, on the other hand, that text is hard-coded in your template files, then you can override it with a child theme. Read about Child Themeing here: https://mediatemple/blog/tips/best-practice-why-and-how-to-create-a-child-theme-in-wordpress/