Created
January 20, 2017 21:01
-
-
Save worduoso/a5bef37aa5d591d4c72fdefd514669e8 to your computer and use it in GitHub Desktop.
How to add custom author's bio to WordPress single post page
This file contains hidden or 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
/* | |
* Add custom contacts for WordPress user as we want user to have links to their Twitter, LinkedIn, etc accounts | |
*/ | |
function worduoso_contactmethods( $contactmethods ) { | |
$contactmethods['linkedin'] = 'Linked In'; // Add LinkedIn | |
$contactmethods['twitter'] = 'Twitter'; // Add Twitter | |
$contactmethods['facebook'] = 'Facebook'; // Add Facebook | |
return $contactmethods; | |
} | |
add_filter('user_contactmethods','worduoso_contactmethods',10,1); | |
/* | |
* Optional: load font awesome to display icons for contact list | |
* you may use custom icons or text instead - just skip the following block. | |
* Also check if your theme already has font awesome to avoid double loading. | |
*/ | |
function worduoso_scripts() { | |
wp_enqueue_style( 'fontawesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css'); | |
} | |
add_action( 'wp_enqueue_scripts', 'worduoso_scripts', 999); |
This file contains hidden or 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 | |
/* | |
* This code should be added to single post template (single.php by default) | |
* we will display custom author's bio only if "description" is set for the user. | |
* I use (optional) markup for the person from https://schema.org in this code. | |
* Also I use FontAwesome to display icons for contact links, e.g. <i class="fa fa-desktop"></i> | |
*/ | |
$description = get_the_author_meta("description"); | |
$facebook = get_the_author_meta("facebook"); | |
$twitter = get_the_author_meta("twitter"); | |
$linkedin = get_the_author_meta("linkedin"); | |
$website = get_the_author_meta("user_url"); | |
?> | |
<div class="blog-author" itemprop="author" itemscope itemtype="http://schema.org/Person"> | |
<?php echo get_avatar( get_the_author_meta('ID'), 200); ?> | |
<h3 itemprop="name"><?php echo get_the_author(); ?></h3> | |
<p><?php echo $description; ?></p> | |
<div class="blog-author-contacts"> | |
<?php if($website) { ?> | |
<a itemprop="url" href="<?php echo $website; ?>"><i class="fa fa-desktop"></i></a> | |
<?php } ?> | |
<?php if($facebook) { ?> | |
<a itemprop="sameAs" href="<?php echo $facebook; ?>"><i class="fa fa-facebook"></i></a> | |
<?php } ?> | |
<?php if($twitter) { ?> | |
<a itemprop="sameAs" href="http://www.twitter.com/<?php echo $twitter; ?>"><i class="fa fa-twitter"></i></a> | |
<?php } ?> | |
<?php if($linkedin) { ?> | |
<a itemprop="sameAs" href="<?php echo $linkedin; ?>"><i class="fa fa-linkedin"></i></a> | |
<?php } ?> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment