使用wordpress同学会注意到,wp提供的默认用户联系资料比较少,无法满足自身网站的需求时。如果要添加用户自定义资料可以通过user_contactmethods
过滤器进行添加。
添加效果
实现代码
/**
* 添加用户联系方式自定义字段
*/
add_filter('user_contactmethods','add_user_field');
function add_user_field( $contactmethods ) {
$contactmethods['u_phone'] = '电话号码';
$contactmethods['u_qq'] = 'QQ号';
$contactmethods['u_weixin'] = '微信号';
return $contactmethods;
}
将上述代码添加到functions.php内进行保存即可。
调用方法:
- 手机号:<?php the_author_meta(‘u_phone’); ?>
- QQ号:<?php the_author_meta(‘u_qq’); ?>
- 微信号:<?php the_author_meta(‘u_weixin’); ?>
也可以用下面的代码来调用信息:
- 手机号:<?php echo $current_user->u_phone; ?>
- QQ号:<?php echo $current_user->u_qq; ?>
- 微信号:<?php echo $current_user->u_weixin; ?>
/** * 添加用户联系方式自定义字段 */ add_filter('user_contactmethods','add_user_field'); function add_user_field( $contactmethods ) { $contactmethods['u_phone'] = '电话号码'; $contactmethods['u_qq'] = 'QQ号'; $contactmethods['u_weixin'] = '微信号'; return $contactmethods; }
将上述代码添加到functions.php内进行保存即可。
调用方法:
- 手机号:<?php the_author_meta(‘u_phone’); ?>
- QQ号:<?php the_author_meta(‘u_qq’); ?>
- 微信号:<?php the_author_meta(‘u_weixin’); ?>
也可以用下面的代码来调用信息:
- 手机号:<?php echo $current_user->u_phone; ?>
- QQ号:<?php echo $current_user->u_qq; ?>
- 微信号:<?php echo $current_user->u_weixin; ?>