Archived topic
Showing Guest Authors Name
9 replies · Started by Kenneth on September 28, 2018
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.
Hi there,
you would need to use a Child Theme to stop it being overwritten when the Theme has an update.
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.
I don´t see custom field which I can modified. In post I see: https://ctrlv.cz/pJne
Hi there,
did you add a Custom Field in the editor?