Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thagxt/9955244 to your computer and use it in GitHub Desktop.
Save thagxt/9955244 to your computer and use it in GitHub Desktop.
Get Author's name outside Loop in WordPress
<?php
global $post;
$author_id=$post->post_author;
?>
<?php
/* You can also use one of these instead:
- nickname
- user_nicename
- display_name
- first_name
- last_name
*/
if( is_single() ) {
the_author_meta( 'nickname', $author_id );
} else {
echo 'Something else';
}
?>
use it in your header:
<?php global $post; $author_id=$post->post_author; ?>
<meta name="author" content="<?php if(is_single()) { the_author_meta( 'nickname', $author_id ); } else { echo 'Something else'; } ?>">
@claytonschase
Copy link

Thank you!

@jeetsinghb
Copy link

Thank You Sir!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment