- This topic has 9 replies, 4 voices, and was last updated 5 years, 10 months ago by
David.
-
AuthorPosts
-
September 28, 2018 at 3:14 am #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.
September 28, 2018 at 8:13 am #688651David
StaffCustomer SupportHi there,
you would need to use a Child Theme to stop it being overwritten when the Theme has an update.
September 28, 2018 at 8:15 am #688654Kenneth
OK, thanks for the reply.
September 28, 2018 at 8:24 am #688661David
StaffCustomer SupportYou’re welcome 🙂
May 12, 2020 at 1:49 pm #1281476Royal 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; }May 12, 2020 at 4:36 pm #1281726Tom
Lead DeveloperLead DeveloperHi 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/
May 12, 2020 at 8:57 pm #1281875Royal 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) ""May 13, 2020 at 9:14 am #1282799Tom
Lead DeveloperLead DeveloperAn empty string means your custom field (
guest-author) doesn’t have a value.May 13, 2020 at 8:40 pm #1283534Royal Rangers
I don´t see custom field which I can modified. In post I see: https://ctrlv.cz/pJne
May 14, 2020 at 9:20 am #1284464David
StaffCustomer SupportHi there,
did you add a Custom Field in the editor?
-
AuthorPosts
- You must be logged in to reply to this topic.