-
AuthorPosts
-
March 22, 2017 at 7:43 am #764630
On single blog posts, I want to replace the author name with a custom-field called guest-author such that the guest-author name appears on the post and on the blog page whenever there is an entry in the guest-author field. If the field is empty, WordPress should use the default author field only.
I found a tutorial online for this, but it doesn’t seem to be working. Also, I checked the code in single.php and couldn’t figure out how to edit it to help with this.
add_filter( ‘the_author’, ‘guest_author_name’ );
add_filter( ‘get_the_author_display_name’, ‘guest_author_name’ );
function guest_author_name( $name ) {
global $post;
$author = get_post_meta( $post->ID, ‘guest-author’, true );
if ( $author )
$name = $author;
return $name;
}Please suggest how I can make this change.
March 23, 2017 at 11:12 am #765312Hey architchandra,
Have you created that additional field and does this function give any error?
add_filter( ‘the_author’, ‘guest_author_name’ ); add_filter( ‘get_the_author_display_name’, ‘guest_author_name’ ); function guest_author_name( $name ) { global $post; $author = get_post_meta( $post->ID, ‘guest-author’, true ); if ( !empty($author) ) return $author; return $name; }
Try adjusting the code like this.
Best regards,
VictoriaAugust 27, 2019 at 12:55 pm #1131309Hi Victoria,
How can I change only for specific posts the wording By “author name” with >>>> translated by “author name” and also changing the author name depending on who the person who translated the post is?Thanks,
MarcoAugust 29, 2019 at 11:19 am #1131853Hi,
Thank you for the update.
You have to edit that directly from includes > loop-index.php file. Look for this code around line 317:
echo '<span class="blog-author minor-meta">'.__('by','avia_framework')." ";
We’re not quite sure about your next inquiry though. How do you translate the posts?
Best regards,
IsmaelAugust 29, 2019 at 1:52 pm #1131876Hi Ismael,
I would like to change the wording “by” with “translated by” not on all posts, only on the ones translated from a language to another. Is your code changing the wording on all posts?I found the answer for the second question, I can change manually the author :-)
- This reply was modified 5 years, 2 months ago by marcoabis81.
September 2, 2019 at 3:38 am #1132772Hi,
Thank you for the update.
Are you using W P M L? You can use this function to check if the current post has a translation or not.
// http://hookr.io/functions/icl_object_id/
Best regards,
IsmaelSeptember 2, 2019 at 4:09 pm #1133047Hi Ismael,
I would like just to change that wording on some posts. I do not need to check if the post has a translation.Example: I have a post in Italian, I pay someone for translating it for me. I would like to show that post with the wording “translated by” instead of just the name of the author.
Thanks
MarcoSeptember 3, 2019 at 4:32 am #1133181Hi,
Do you want to add another name beside the author? Maybe you can use custom fields for that. This plugin might help.
// https://www.advancedcustomfields.com/
Enable the plugin, edit the post, add a custom field called “translated_by” and use the name of the translator as the value. In the includes > loop-index.php, get the custom field using the get_field function. Above this code:
echo '<span class="blog-author minor-meta">'.__('by','avia_framework')." ";
..add this:
$translated_by = get_field('translated_by'); echo '<span class="blog-translator minor-meta">'.__('translated by','avia_framework')." "; echo '<span class="entry-translator">'; if($translated_by) echo $translated_by; echo '</span></span>';
// https://www.advancedcustomfields.com/resources/get_field/
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.