Add/remove contact info fields

Wordpress Users Custom Fields
language: PHP
license: Other

Code for Snippet:

                
User profiles in WordPress by default have these fields for Contact Info by default: E-mail, Website, AIM, Yahoo IM, Jabber / Google Talk. You can remove those and add new ones as you wish, like in this example code for your functions.php file in your theme:
 
<?php
	function wptuts_contact_methods( $contactmethods ) {
 
		// Remove we what we don't want
		unset( $contactmethods[ 'aim' ] );
		unset( $contactmethods[ 'yim' ] );
		unset( $contactmethods[ 'jabber' ] );
 
		// Add some useful ones
		$contactmethods[ 'twitter' ] = 'Twitter Username';
		$contactmethods[ 'facebook' ] = 'Facebook Profile URL';
		$contactmethods[ 'linkedin' ] = 'LinkedIn Public Profile URL';
		$contactmethods[ 'googleplus' ] = 'Google+ Profile URL';
 
		return $contactmethods;
	}
 
	add_filter( 'user_contactmethods', 'wptuts_contact_methods' );
 
	function wptuts_linkedin( $author ) {
		$authorinfo = get_user_meta( $author );
		$linkedin = $authorinfo['linkedin'][0];
 
		if ( isset( $linkedin ) ) : ?>
			<script type="IN/MemberProfile" data-id="<?php echo $linkedin; ?>" data-format="hover" data-related="false"></script>
		<?php endif;
	}
 
	function wptuts_linkedin_js() {
		if ( is_single() || is_author() ) :
			wp_enqueue_script( 'linkedin', '//platform.linkedin.com/in.js', null, null, true );
		endif;
	}
 
	add_action( 'wp_enqueue_scripts', 'wptuts_linkedin_js' );
 
 
<?php
				// If a user has filled out their description, show a bio on their entries.
				if ( get_the_author_meta( 'description' ) ) : ?>
					<div class="author-info">
						<div class="author-avatar">
							<?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentytwelve_author_bio_avatar_size', 60 ) ); ?>
						</div><!-- .author-avatar -->
						<div class="author-description">
							<h2><?php printf( __( 'About %s', 'twentytwelve' ), get_the_author() ); ?></h2>
							<p><?php the_author_meta( 'description' ); ?></p>
 
							<div class="profile-links">
 
								<ul class="social-links">
									<?php if ( get_the_author_meta( 'twitter' ) != '' )  { ?>
										<li><a class="twitter-link" href="https://twitter.com/<?php echo wp_kses( get_the_author_meta( 'twitter' ), null ); ?>"><?php printf( esc_attr__( 'Follow %s on Twitter', 'tuts_plus'), get_the_author() ); ?></a></li>
									<?php } ?>
 
									<?php if ( get_the_author_meta( 'facebook' ) != '' )  { ?>
										<li><a class="facebook-link" href="<?php echo esc_url( get_the_author_meta( 'facebook' ) ); ?>"><?php printf( esc_attr__( 'Follow %s on Facebook', 'tuts_plus'), get_the_author() ); ?></a></li>
									<?php } ?>
 
									<?php if ( get_the_author_meta( 'linkedin' ) != '' )  { ?>
										<li class="linkedin-link"><?php wptuts_linkedin( get_the_author_meta( 'ID' )); ?></li>
									<?php } ?>
 
									<?php if ( get_the_author_meta( 'googleplus' ) != '' )  { ?>
										<li><a class="google-link" href="<?php echo esc_url( get_the_author_meta( 'googleplus' ) ); ?>"><?php printf( esc_attr__( 'Follow %s on Google+', 'tuts_plus'), get_the_author() ); ?></a></li>
									<?php } ?>
								</ul>
 
								<div class="clear"></div>
 
							</div>
						</div><!-- .author-description	-->
					</div><!-- .author-info -->
				<?php endif; ?>
 
//or single page
<div class="media profile">
 
						<?php echo get_avatar( get_the_author_meta('ID'), '70' );?>
 
						<div class="bd">
 
							<h4><?php printf( esc_attr__( 'About %s', 'tuts_plus' ), get_the_author() );?></h4>
 
							<p><?php echo wp_kses( get_the_author_meta( 'description' ), null ); ?></p>
 
							<div class="profile-links">
 
								<ul class="social-links">
									<?php if ( get_the_author_meta( 'twitter' ) != '' )  { ?>
										<li><a class="twitter-link" href="https://twitter.com/<?php echo wp_kses( get_the_author_meta( 'twitter' ), null ); ?>"><?php printf( esc_attr__( 'Follow %s on Twitter', 'tuts_plus'), get_the_author() ); ?></a></li>
								    <?php } ?>
 
									<?php if ( get_the_author_meta( 'facebook' ) != '' )  { ?>
										<li><a class="facebook-link" href="<?php echo esc_url( get_the_author_meta( 'facebook' ) ); ?>"><?php printf( esc_attr__( 'Follow %s on Facebook', 'tuts_plus'), get_the_author() ); ?></a></li>
									<?php } ?>
 
									<?php if ( get_the_author_meta( 'linkedin' ) != '' )  { ?>
										<li class="linkedin-link"><?php wptuts_linkedin( get_the_author_meta( 'ID' )); ?></li>
									<?php } ?>
 
									<?php if ( get_the_author_meta( 'googleplus' ) != '' )  { ?>
										<li><a class="google-link" href="<?php echo esc_url( get_the_author_meta( 'googleplus' ) ); ?>"><?php printf( esc_attr__( 'Follow %s on Google+', 'tuts_plus'), get_the_author() ); ?></a></li>
									<?php } ?>
								</ul>
 
								<div class="clear"></div>
 
								<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>">
									<?php printf( __( 'View all posts by %s <span class="meta-nav">&rarr;</span>', 'tuts_plus' ), get_the_author() ); ?>
								</a>
 
							</div>
 
						</div>
 
					</div>
comments powered by Disqus

Info

Tags: Wordpress

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 5008
Date Added: 2013-03-08 14:48:23
Last Modified: 2013-03-15 10:23:00

Web Analytics