Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created December 26, 2017 18:44
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 tripflex/05894b38a962c408c496f23e30993299 to your computer and use it in GitHub Desktop.
Save tripflex/05894b38a962c408c496f23e30993299 to your computer and use it in GitHub Desktop.
Custom shortcode to output Post Author (First and Last Name) on Custom Post Types (Job Listings, Resumes, etc).
<?php
// ^ only ONE of these should be at the top of child theme's functions.php file
add_shortcode( 'smyles_post_author_name', 'smyles_custom_output_post_author_name' );
function smyles_custom_output_post_author_name( $args = array(), $content = '' ){
$post_author = get_post_field( 'post_author', get_the_ID() );
if( empty( $post_author ) ) return '';
$author_fname = get_the_author_meta( 'first_name', $post_author );
$author_lname = get_the_author_meta( 'last_name', $post_author );
return "{$author_fname} {$author_lname}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment