Skip to content

Instantly share code, notes, and snippets.

@diggeddy
Last active November 2, 2021 16:25
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 diggeddy/c448f642993866f79dbb960cbc450a6a to your computer and use it in GitHub Desktop.
Save diggeddy/c448f642993866f79dbb960cbc450a6a to your computer and use it in GitHub Desktop.
Create a simple author box shortcode
<?php
// Simple Author Box Shortcode
add_shortcode( 'db_author_box', 'db_author_box_shortcode' );
function db_author_box_shortcode() {
ob_start();
// Check if is Single Post
if ( is_single() ) {
global $post;
?>
<div class="author-box">
<div class="avatar"><?php echo get_avatar( get_the_author_meta( 'ID' )); ?></div>
<h5 class="author-title"><?php printf( esc_attr__( 'About %s', 'the author' ), get_the_author_meta( 'display_name') );?></h5>
<div class="author-summary">
<p class="author-description"><?php echo wp_kses( get_the_author_meta( 'description' ), null ); ?></p>
<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>" class="button author-link" title="Read more">Read More</a>
</div>
</div>
<?php
}
return ob_get_clean();
}
?>
<style>
.author-box .avatar {
width: 40px;
border-radius: 40px;
margin-right: 10px;
vertical-align: middle;
}
.author-box .avatar,
.author-box .author-title {
display: inline-block;
}
.author-box .author-summary,
a.author-links {
font-size: 13px;
}
.author-summary a.author-link {
padding: 4px 8px;
border-radius: 4px
}
</style>
@wpsyed
Copy link

wpsyed commented Nov 2, 2021

Thanks found it to be very helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment