Skip to content

Instantly share code, notes, and snippets.

@braddalton
Created May 30, 2014 05:29
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 braddalton/2b2d096e63c1f2852aa9 to your computer and use it in GitHub Desktop.
Save braddalton/2b2d096e63c1f2852aa9 to your computer and use it in GitHub Desktop.
add_shortcode( 'post_author_posts_link', 'genesis_post_author_posts_link_shortcode' );
/**
* Produces the author of the post (link to author archive).
*
* Supported shortcode attributes are:
* after (output after link, default is empty string),
* before (output before link, default is empty string).
*
* Output passes through 'genesis_post_author_posts_link_shortcode' filter before returning.
*
* @since 1.1.0
*
* @param array|string $atts Shortcode attributes. Empty string if no attributes.
* @return string Shortcode output
*/
function genesis_post_author_posts_link_shortcode( $atts ) {
$defaults = array(
'after' => '',
'before' => '',
);
$atts = shortcode_atts( $defaults, $atts, 'post_author_posts_link' );
$author = get_the_author();
$url = get_author_posts_url( get_the_author_meta( 'ID' ) );
if ( genesis_html5() ) {
$output = sprintf( '<span %s>', genesis_attr( 'entry-author' ) );
$output .= $atts['before'];
$output .= sprintf( '<a href="%s" %s>', $url, genesis_attr( 'entry-author-link' ) );
$output .= sprintf( '<span %s>', genesis_attr( 'entry-author-name' ) );
$output .= esc_html( $author );
$output .= '</span></a>' . $atts['after'] . '</span>';
} else {
$link = sprintf( '<a href="%s" title="%s" rel="author">%s</a>', esc_url( $url ), esc_attr( $author ), esc_html( $author ) );
$output = sprintf( '<span class="author vcard">%2$s<span class="fn">%1$s</span>%3$s</span>', $link, $atts['before'], $atts['after'] );
}
return apply_filters( 'genesis_post_author_posts_link_shortcode', $output, $atts );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment