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










