Guest Posts And the_author() In Your WordPress Blog
As you may have seen I have a guest post on this blog written by Matt from phuketvogue.com. Since I am the only registered writer/author on this site, all posts are marked as ‘written by Toxane’ or something similar. I thought it would be just fair for the guest writer, to mark these posts with the corresponding author name and a link back to the author’s site.
What I didn’t want was to have the guest authors as registered WordPress users on my blog, just to keep things simple (and save). I came up with the following solution:
In my theme folder I have my ‘functions.php’ file and I added the following code to it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | // Guest Posts function theAuthor() { $guestName = get_post_custom_values("guestName"); $guestLink = get_post_custom_values("guestLink"); if ($guestName) { if ($guestLink) { echo '<a href="'.$guestLink[0].'" target="_blank">'.$guestName[0].'</a>'; } else { echo $guestName[0]; } } else { the_author(); } } |
The code checks if the post has a custom field ‘guestName’. If the field is found, the code further checks if there’s a custom field ‘guestLink’. If that field is found as well, the code returns the name of the guest author as a hyperlink back to the guest authors website. If there’s no ‘guestLink’, only the guest author’s name is returned. If both custom fields are missing, the code returns ‘the_author()’ which is the registered WordPress user.
Next I replaced all occurences of ‘the_author()’ in the theme files with ‘theAuthor()’
To mark any post in your WordPress Blog as a guest post, you just add a custom field ‘guestName’ and the name of the guest author as value. If you want the guest author’s name appears as a hyperlink, just add a custom field ‘guestLink’ and the web address of the guest author as value.
That’s it. Simple and fair for your guest author(s).

Hi, I have just started a WP blog on Travel to Pattaya, I have been looking for ways to encourage guest writers to contribute every little bit like this tip will help so thanks
What are directions shown to guest poster? How are the custom fields put into post? Is post held for admin review? I lack your programming depth for WP.
@Mugger
The idea is that the guest author sends his post by email as you are the sole user on your blog. After you have received the writing by mail, you add the post to WP by yourself ( copy + paste ) and add the two custom field keys & values for the guest author’s name and email.
HTH
Very nice, very quick… Thanks for sharing :)
For some reason, even when I add a new contributor account, and add an article under another author, the_author still displays the main admin account as the author… But your method fixes that!
How did you know that I was looking out for this? :-) Perfect solution for single author blogs with occasional guest posts. Why don’t you convert it into a plugin?
This is a very useful hack. I haven’t managed to make it work on the blog I’m building – but then I’m very new to this.
A question:
“Next I replaced all occurences of ‘the_author()’ in the theme files with ‘theAuthor()’”
Why is this necessary? How many occurances a ‘the_author()’ are there in the theme files? This seems like a tremendous amount of work compared to the very elegant one-step conditional hack for the function.php. Or am I missing something?
Thanks you for clarifying.
@Warren
In my previous theme I had two occurrences of ‘the_author()’ (index.php, single.php). In the WordPress default theme (themes/default) is only one occurrence (index.php). So, a manual replace is done within one or two minutes. If you have access to a HTML Editor such as Dreamweaver, there is usually a search/replace function available which will do the magic for you.
The reason to replace the function call is that we cannot declare two functions with the same name, hence the new function name ‘theAuthor()’ because ‘the_author()’ is already declared in the WordPress core files (wp-includes/author-template.php).
HTH
Pete
I want to apologize for not replying to your helpful response so long ago. Thanks again for this elegant solution!
Warren
Neat workaround for the template tags, but what about Author archives? If you would have them, surely the guest post would be included on your author archive.
Perhaps a workaround might be to drop posts for which $guestname is set — or to mark them in a special way.
(In fact you do have author archives automatically — http://www.flowdrops.com/blog/author/Pete/ )
Sorry, I keep coming back with second thoughts. The most elegant workaround for author archives would probably be to make one other guest account and assign all guest posts to this account; then getting the custom fields if they are set, and otherwise
the_author().I have searched all the files in my theme folder but could not find a single occurrence of ‘the_author()’. Is this normal? Hence i still show up as the author of the post.
@ Mark
Thanks for the input. Your third comment would be a nice solution!
@Ammar Awaad
Maybe your theme uses another function call to display the Author’s name. Also see:
http://codex.wordpress.org/Template_Tags/the_author
Scusate, non so dove va inserito: o php the_author(); per far si che venga visualizzato l’autore del post in auto. Resto in attesa…Grazie
I realize this is a really old post, however, I’m greatful for it. you can check it out in action at http://jwge.org/gp_fastfood/
Thanks!
Glad it helped you & thanks for the ‘showcase’! ;-)
i actually found this post searching for that exact problam in google, and you gave me a perfect solution.. thanks alot!
i’m joining the call for making this a plugin, you should get thousands of links if you post a download link for this on you blog, me thinks.
anyways, thanks!