Home › Forums › Support › Display different authot's name translations depending on language version
- This topic has 3 replies, 2 voices, and was last updated 3 years, 11 months ago by Tom.
-
AuthorPosts
-
May 6, 2020 at 11:41 am #1272580Oleksiy
Hi, guys,
Could you please help me with the following problem.
I’d like to dislay different translations of the author’s name across different language versions. Because it actually has a different spelling. Including Cyryllic.First of all I use the code from here https://docs.generatepress.com/article/generate_post_author_output/ to remove a link. After this I use the following code:
add_filter( 'generate_post_author_output', 'alex_translate_name' ); function alex_translate_name() { if (get_locale() == 'ru_RU') { return 'My name in Russian'; } if (get_locale() == 'uk') { return 'My name in Ukrainian'; } if (get_locale() == 'en_US') { return 'My name in English'; } }
or this one just to check:
add_filter( 'generate_post_author_output', function( $output ) { return 'My name in Ukrainian'; } );
Result is the same. One more author’s name is being added to the already displayed. No replacement.
It’s at the end of the post.How can I fix it?
May 6, 2020 at 5:26 pm #1272928TomLead DeveloperLead DeveloperHi there,
It shouldn’t be appending to the existing author – make sure you’re not using another function with the same filter.
You should be able to do this:
add_filter( 'generate_post_author_output', function( $output ) { $author_name = 'Your name'; if (get_locale() == 'ru_RU') { $author_name = 'Your name in Russian. } return sprintf( '<span class="byline">%1$s<span class="author vcard" %5$s><a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span></span> ', apply_filters( 'generate_inside_post_meta_item_output', '', 'author' ), esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), /* translators: 1: Author name */ esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), $author_name ) ), $author_name, generate_get_microdata( 'post-author' ) ); } );
May 7, 2020 at 3:15 am #1273358OleksiyHi, Tom
update: looks like at last I fixed it. Thanks. Your solution helped to update mine.
But I leave the text below to explain what exactly code above is actually doing. In case if somebody is searching exactly for this.Language versions are working. But avatar disappeared, “author” word is visible, and a link to all author’s posts is present.
May 7, 2020 at 10:07 am #1274133TomLead DeveloperLead DeveloperGlad you got it working 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.