The WordPress user profile screen allows you to set values for social services but some default services are irrelevant, namely AIM and Yahoo! IM; ?add to that the fact that Twitter and Facebook fields are missing. ?You quickly realize tha
the wordpress user profile screen allows you to set values for social services but some default services are irrelevant, namely aim and yahoo! im; ?add to that the fact that twitter and facebook fields are missing. ?you quickly realize that the default form…needs work. ?wordpress provides a method for adding and removing profile fields. ?let me show you how it works!
The first step is creating a function in your functions.php file which will accept an array of profile keys and values:
function modify_contact_methods($profile_fields) {
// Field addition and removal will be done here
}
add_filter('user_contactmethods', 'modify_contact_methods');
This function provides access to that important protected array. ?The returned value becomes the list of user profile fields.
Adding a new field, Twitter handle for example, includes adding a key to the passed in array, with a value which will act as the field label:
function modify_contact_methods($profile_fields) {
// Add new fields
$profile_fields['twitter'] = 'Twitter Username';
$profile_fields['facebook'] = 'Facebook URL';
$profile_fields['gplus'] = 'Google+ URL';
return $profile_fields;
}
add_filter('user_contactmethods', 'modify_contact_methods');
Simply adding that key/value to the array adds a new field to the form.
Conversely, removing a key from said array removes a field from the user profile form:
function modify_contact_methods($profile_fields) {
// Add new fields
$profile_fields['twitter'] = 'Twitter Username';
$profile_fields['facebook'] = 'Facebook URL';
$profile_fields['gplus'] = 'Google+ URL';
// Remove old fields
unset($profile_fields['aim']);
return $profile_fields;
}
add_filter('user_contactmethods', 'modify_contact_methods');
The code above removes the AIM field from the edit profile form.
To retrieve custom field values, use the?get_the_author_meta method:
// Retrieve a custom field value
$twitterHandle = get_the_author_meta('twitter');
The ability to easily add profile form fields is awesome; ?super easy to do, no plugin required!
Read the full article at: Add and Remove Profile Fields to WordPress User Form


全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等
C++高性能并发应用_C++如何开发性能关键应用
Java AI集成Deep Java Library_Java怎么集成AI模型部署
Golang后端API开发_Golang如何高效开发后端和API
Python异步并发改进_Python异步编程有哪些新改进
C++系统编程内存管理_C++系统编程怎么与Rust竞争内存安全
Java GraalVM原生镜像构建_Java怎么用GraalVM构建高效原生镜像
Python FastAPI异步API开发_Python怎么用FastAPI构建异步API
C++现代C++20/23/26特性_现代C++有哪些新标准特性如modules和coroutines
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号