Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save celticwebdesign/454578b3edd8b17fb3bd to your computer and use it in GitHub Desktop.
Save celticwebdesign/454578b3edd8b17fb3bd 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;
// echo gettype( $author_id );
// echo "<pre>";
// print_r( $author_id );
// echo "</pre>";
// https://codex.wordpress.org/Function_Reference/the_author_meta
// Get Author's name outside Loop in WordPress.php
// https://gist.github.com/thagxt/9955244
echo " - ";
the_author_meta( 'display_name', $author_id );
?>
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