用户个人资料的联系信息里,默认有邮箱、站点、AIM、雅虎通和 Jabber,而有些东西我们可能都没听说过,所以去除是非常有必要的。本文就来教你,怎么自定义这些信息的项目。
下边的代码删除了 AIM、雅虎通和 Jabber,添加了新浪微博、腾讯微博和 QQ 这些国内比较常用的社交网络。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /** *WordPress 自定义用户联系信息的项目 *http://www.moke8.com/ */ function Bing_change_user_contact_information( $fields ){ unset( $fields['aim'] ); unset( $fields['yim'] ); unset( $fields['jabber'] ); $fields['weibo'] = '新浪微博'; $fields['t_weibo'] = '腾讯微博'; $fields['qq'] = '腾讯 QQ'; return $fields; } add_filter( 'user_contactmethods', 'Bing_change_user_contact_information' ); |
想获取这些信息只要使用 get_the_author_meta() 函数即可。
1 2 3 | $weibo = get_the_author_meta( 'weibo', $user_id );//新浪微博 $t_weibo = get_the_author_meta( 't_weibo', $user_id );//腾讯微博 $qq = get_the_author_meta( 'qq', $user_id );//腾讯 QQ |