Site logo

Archived topic

Showing Guest Authors Name

9 replies · Started by Kenneth on September 28, 2018

Viewing posts 1–10 of 10

OK, thanks for the reply.

You're welcome :)

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;
}

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/

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) ""

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

This archived topic is closed to new replies.