Skip to content

Instantly share code, notes, and snippets.

@BinaryMoon
Created September 2, 2016 21:01
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 BinaryMoon/9519f12d0b1e7920fdc7984b4eb0046c to your computer and use it in GitHub Desktop.
Save BinaryMoon/9519f12d0b1e7920fdc7984b4eb0046c to your computer and use it in GitHub Desktop.
Alternate version of author-bio.php that separates the author bio into a separate function so that the same code can be used in other template files
<?php
/**
* The function to display Author Bio in a theme.
*/
function jetpack_author_bio() {
// If the theme doesn't support 'jetpack-content-options', don't continue.
if ( ! current_theme_supports( 'jetpack-content-options' ) ) {
return;
}
$options = get_theme_support( 'jetpack-content-options' );
$author_bio = ( ! empty( $options[0]['author-bio'] ) ) ? $options[0]['author-bio'] : null;
// If the theme doesn't support 'jetpack-content-options[ 'author-bio' ]', don't continue.
if ( true !== $author_bio ) {
return;
}
// If 'jetpack_content_author_bio' is false and we aren't in the customizer, don't continue.
if ( ! get_option( 'jetpack_content_author_bio', 1 ) && ! is_customize_preview() ) {
return;
}
// If we aren't on a single post, don't continue.
if ( ! is_single() ) {
return;
}
jetpack_author_bio_html();
}
/**
* Display Author Biography
*/
function jetpack_author_bio_html( $user_id = null ) {
// If no user id set then get th user for the current post.
if ( ! $user_id ) {
$user_id = get_the_author_meta( 'ID' );
}
?>
<div class="entry-author">
<div class="author-avatar">
<?php
/**
* Filter the author bio avatar size.
*
* @param int $size The avatar height and width size in pixels.
*/
$author_bio_avatar_size = apply_filters( 'jetpack_author_bio_avatar_size', 48 );
echo get_avatar( $user_id, $author_bio_avatar_size );
?>
</div><!-- .author-avatar -->
<div class="author-heading">
<h2 class="author-title"><?php printf( esc_html__( 'Published by %s', 'jetpack' ), '<span class="author-name">' . the_author_meta( 'display_name', $user_id ) . '</span>' ); ?></h2>
</div><!-- .author-heading -->
<p class="author-bio">
<?php the_author_meta( 'description' ); ?>
<a class="author-link" href="<?php echo esc_url( get_author_posts_url( $user_id ) ); ?>" rel="author">
<?php printf( esc_html__( 'View all posts by %s', 'jetpack' ), the_author_meta( 'display_name', $user_id ) ); ?>
</a>
</p><!-- .author-bio -->
</div><!-- .entry-auhtor -->
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment