Display Guest Author’s Name via Custom Field

Posted by ADMIN On 5:08 AM
Many Blogs are now having guest posts on their site. Some of these guest authors are one-time only authors, so there is no point in creating a separate profile for them just so you can display their name in the post. The smarter way to do this is by using the following code.

Open you single.php, or page.php in your template and add the following code where you display the author name:

    <?php $author = get_post_meta($post->ID, "guest-author", true);
    if ($author != "") {
    echo $author;
    } else {
    the_author();
    } ?>

This code will look for the custom field called guest-author if it is found, then it will display that name, otherwise it will display the_author function meaning the person who actually published it meaning you.

Note: You might have to remove the original the_author function before you place this.

0 Response to "Display Guest Author’s Name via Custom Field"

Post a Comment

Google Translator

Search Box

Blog Archive

User Status

Free counters!

About Me

ADMIN
Pakistan
View my complete profile

Recent Posts

Recent Comments