Site logo

[Support request] Showing Guest Authors Name

Home Forums Support [Support request] Showing Guest Authors Name

Home Forums Support Showing Guest Authors Name

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #688402
    Kenneth

    I would like to show a guest authors name instead of my own in certain articles and would prefer to do it without using a plugin. I found this article at Wp Beginner (https://www.wpbeginner.com/wp-tutorials/how-to-rewrite-guest-author-name-with-custom-fields-in-wordpress/) however if editing the function.php would it not be overwritten with GeneratePress updates?

    Appreciate any advice you could offer. Thanks.

    #688651
    David
    Staff
    Customer Support

    Hi there,

    you would need to use a Child Theme to stop it being overwritten when the Theme has an update.

    https://docs.generatepress.com/article/using-child-theme/

    #688654
    Kenneth

    OK, thanks for the reply.

    #688661
    David
    Staff
    Customer Support

    You’re welcome 🙂

    #1281476
    Royal Rangers

    Hi, sorry for re-open. I try this code in functions.php of child theme. I seeing my name, not guest in post.

    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;
    }
    #1281726
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Let’s debug the code:

    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 );
        var_dump($author);
        if ( $author ) {
            $name = $author;
        }
     
        return $name;
    }

    Does that output anything?

    Alternatively, this might help: https://wordpress.org/plugins/guest-author/

    #1281875
    Royal Rangers

    Not works. I see this error.

    string(0) "" string(0) ""
    Warning: Cannot modify header information - headers already sent by (output started at web/generatepress-child-theme/functions.php:99) in web/wp-admin/admin-header.php on line 9
    string(0) ""
    #1282799
    Tom
    Lead Developer
    Lead Developer

    An empty string means your custom field (guest-author) doesn’t have a value.

    #1283534
    Royal Rangers

    I don´t see custom field which I can modified. In post I see: https://ctrlv.cz/pJne

    #1284464
    David
    Staff
    Customer Support

    Hi there,

    did you add a Custom Field in the editor?

    https://wordpress.org/support/article/custom-fields/

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