Created
December 26, 2017 18:44
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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