Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #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.

    #765312

    Hey 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,
    Victoria

    #1131309

    Hi 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,
    Marco

    #1131853

    Hi,

    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,
    Ismael

    #1131876

    Hi 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.
    #1132772

    Hi,

    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,
    Ismael

    #1133047

    Hi 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
    Marco

    #1133181

    Hi,

    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

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.