Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bosunolanrewaju/b473d09fc861920987859666617116a7 to your computer and use it in GitHub Desktop.
Save bosunolanrewaju/b473d09fc861920987859666617116a7 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'; } ?>">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment