Skip to content

Instantly share code, notes, and snippets.

@chriswagoner
Created March 13, 2018 19:22
Show Gist options
  • Save chriswagoner/8159393e9412043e1e483d8add392583 to your computer and use it in GitHub Desktop.
Save chriswagoner/8159393e9412043e1e483d8add392583 to your computer and use it in GitHub Desktop.
Get Author of Current Post
add_shortcode('author-name', 'author_name_shortcode_handler');
function author_name_shortcode_handler($atts,$content=null){
if (!is_single()) return;
global $wp_query;
$user_id = $wp_query->post->post_author;
$name = get_user_meta($user_id, 'first_name', true) . ' ' . get_user_meta($user_id, 'last_name', true);
if (!empty($name))
return $name;
else
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment