Family Best Time >> Electronics

How to rewrite guest author name with custom fields in WordPress

Have you ever had a guest post on your blog? How are you going to give full credit to the author? We have seen many sites where they add an author profile box, either above the post or below the post. But even with the guest author box, the author name field will still show the author of the site. Some bloggers create entirely new author profiles for their guest authors in order to display the correct name. We believe there is no point in creating additional user profiles if you know that this guest author will only post once.

The trick we're sharing in this article will allow you to display the guest author's name simply by entering a custom field in your post.

Open your functions.php file and paste the following codes:

 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) $ nombre = $ autor; devuelve $ nombre; 

Now, whenever you publish a guest post, make sure to add a custom field called guest author and it will replace the author name with the text you put in that custom field.

Example:

How to rewrite guest author name with custom fields in WordPress