21 May 2017

Modifying Wordpress user info

The following adds a bunch of usefull social media links to the wordpress user profiles - and also allows simple HTML within the user bio. Add this code to the theme functions.php file.

/*===================================================================================
* Add Author Links
* =================================================================================*/
function add_to_author_profile( $contactmethods ) {

$contactmethods['rss_url'] = 'RSS URL';
$contactmethods['google_profile'] = 'Google Profile URL';
$contactmethods['twitter_profile'] = 'Twitter Profile URL';
$contactmethods['facebook_profile'] = 'Facebook Profile URL';
$contactmethods['instagram_profile'] = 'Instagram Profile URL';
$contactmethods['linkedin_profile'] = 'Linkedin Profile URL';

return $contactmethods;
}
add_filter( 'user_contactmethods', 'add_to_author_profile', 10, 1);
//disable WordPress sanitization to allow more than just $allowedtags from /wp-includes/kses.php
remove_filter('pre_user_description', 'wp_filter_kses');
//add sanitization for WordPress posts
add_filter( 'pre_user_description', 'wp_filter_post_kses');

 

Now dial it all up within the author.php file of your theme with the following code:

<div id="description" class="node"><?php the_author_meta('description'); ?></div>


<ul class="icons">
<?php
$site = get_the_author_meta( 'user_url' );
if ( $site && $site != '' ) {
echo '<li class="site"><a target="_blank" href="' . esc_url($site) . '">Website</a></li>';
}


$rss_url = get_the_author_meta( 'rss_url' );
if ( $rss_url && $rss_url != '' ) {
echo '<li class="rss"><a target="_blank" href="' . esc_url($rss_url) . '">RSS</a></li>';
}

$google_profile = get_the_author_meta( 'google_profile' );
if ( $google_profile && $google_profile != '' ) {
echo '<li class="google"><a target="_blank" href="' . esc_url($google_profile) . '" rel="author">Google+</a></li>';
}

$twitter_profile = get_the_author_meta( 'twitter_profile' );
if ( $twitter_profile && $twitter_profile != '' ) {
echo '<li class="twitter"><a target="_blank" href="' . esc_url($twitter_profile) . '">Twitter</a></li>';
}

$facebook_profile = get_the_author_meta( 'facebook_profile' );
if ( $facebook_profile && $facebook_profile != '' ) {
echo '<li class="facebook"><a target="_blank" href="' . esc_url($facebook_profile) . '">Facebook</a></li>';
}

$linkedin_profile = get_the_author_meta( 'linkedin_profile' );
if ( $linkedin_profile && $linkedin_profile != '' ) {
echo '<li class="linkedin"><a target="_blank" href="' . esc_url($linkedin_profile) . '">Linkedin</a></li>';
}

$instagram_profile = get_the_author_meta( 'instagram_profile' );
if ( $instagram_profile && $instagram_profile != '' ) {
echo '<li class="Instagram"><a target="_blank" href="' . esc_url($instagram_profile) . '">Instagram</a></li>';
}
?>
</ul>