2

How To Add A Twitter Field In User Profiles And Remove YIM

Ever wondered why Wordpress has some of the profile fields it has like Yahoo Instant Message or Jabber? Wouldn't it be better to replace the ones you don't use with something you would use? In this tutorial I'll show you how you can easily learn how to remove the Yahoo IM field and add a field for your Twitter username, including what you have to do to show the value of that field in your them...
How To Add A Twitter Field In User Profiles And Remove YIM

Who uses Yahoo IM anyways?

Hey I do. Well not really, but I have an account. It's a useless field, just like the other instant messenger user name fields on your profile page in the WP dashboard. You can replace them all using this method.

How to customize your WordPress profile fields

In your theme directory, open up the functions.php file, and add this code to it, save and re-upload it.


// Add Twitter profile field and remove Yahoo IM
function add_twitter_contactmethod( $contactmethods ) {
	// Add Twitter
	$contactmethods['twitter'] = 'Twitter';

	// Remove Yahoo IM
	unset($contactmethods['yim']);

	return $contactmethods;
}
add_filter('user_contactmethods','add_twitter_contactmethod',10,1);

What this code does:

The function add_twitter_contactmethod() is asking for the value of the variable $contactmethods.
It sets the variable to 'twitter'.
Removes, or unsets 'yim' as the variable.
Then returns what the new variable is set to which is twitter.
The last part is the hook needed to modify the database table. Read more on add_filter() here.

Add a link to your Twitter page in your theme

Say you wanted add a link to the post authors Twitter page like in the author bio at the bottom of this post. You need to get that information and display it. Using the function the_author_meta() you can get the value of whatever profile field you choose for the author of a post. But first we need check if it exists with get_the_author_meta().

You can add this in whatever template file you want, depending where you want it to show. You could create a custom function and put this in it, then call the function in your theme as well if you wanted.


if (get_the_author_meta('twitter')) { // check if there is a value to get 

	<a href="http://twitter.com/<?php the_author_meta('twitter'); ?>" title="Follow <?php the_author_meta('display_name'); ?> on Twitter" target="_blank" class="twitter">Follow <?php the_author_meta('display_name'); ?> on Twitter</a>

php } // End check for twitter

In order to replace other fields you don't use in profiles you just do the same thing as this except using different names according to what you're removing/adding.

Do you wish there were more options available to use more easily on the profile page?

Shortlink:

Get automatic updates! Subscribe to Our RSS Feed or Get Email Updates sent straight to your inbox!

About the Author

Jared is from Boston working as a web and graphic designer. Also owns the design blog Tweeaks.com, and has designed many other websites powered by Wordpress including the New2WP theme.

Level: Rookie

User Comments

( ADD YOURS )

  1. Thanks for this useful tip Jared - I always wondered why there was no Twitter field. And I HATE yim, such a useless service. This will be getting a lot of use from me here on out - thanks again.


  2. Hey Jared. I tried adding that line to my WP site and it's didn't show up. I'm not sure if it is relevant but the theme I'm using is "vicuna."

    TIA! :)

Trackbacks


  1. Avatar

    Your Name
    February 4


    CommentLuv badge