前几天有人问本站,怎么在我的个人资料这个页面添加其他的字段呢?例如:QQ号码、微信号码之类的input表单输入框。
WordPress默认的设置里是没有QQ号码、微信号码的,如果要添加我们只能使用代码添加自定义字段,有很多插件可以实现这个功能,但是能不用插件就不用插件嘛,今天本站分享一篇免插件纯代码实现个人资料添加自定义字段的WordPress教程。
添加用户自定义字段
首先我们在我的个人资料编辑页面添加一行“微信号码”的自定义字段。
直接把下面的代码复制到主题的functions.php文件中,即可在用户资料编辑页面看到一个“QQ号码”的表单项。
add_action( 'show_user_profile', 'wizhi_extra_user_profile_fields' );
add_action( 'edit_user_profile', 'wizhi_extra_user_profile_fields' );
add_action( 'personal_options_update', 'wizhi_save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'wizhi_save_extra_user_profile_fields' );
function wizhi_save_extra_user_profile_fields( $user_id ){
if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
update_user_meta( $user_id, 'wx_username', $_POST['wx_username'] );
}
function wizhi_extra_user_profile_fields( $user ){ ?>
附加用户字段
请输入微博用户名。
调用自定义字段
添加好用户自定义字段后,如何获取使用这个字段呢?获取的方法也很简单,示例代码如下:
ID, 'wx_username', true);
?>
把上面的调用自定义字段添加到想要显示用户字段内容的页面即可。
文章来源于互联网:WordPress个人资料添加自定义字段input表单
I’m not positive the place you’re getting your info, but good topic.
I needs to spend some time learning much more or figuring out more.
Thank you for magnificent info I used to be looking for this info for my
mission.
my page :: tracfone special
Hi, Neat post. There’s an issue along with your site in web explorer,
might check this? IE nonetheless is the marketplace leader and a huge section of other folks will pass over your magnificent writing because of this problem.
my website – tracfone special coupon 2022
continuously i used to read smaller content which also clear their motive, and that is also happening with this piece of writing which I am reading
at this place.
My webpage … tracfone special coupon 2022
What’s up it’s me, I am also visiting this site on a regular basis, this web site
is in fact nice and the people are genuinely sharing nice
thoughts.
Hi, i feel that i saw you visited my site thus i got here to return the prefer?.I am trying to in finding issues to improve my site!I guess its
good enough to use a few of your ideas!!
Simply wish to say your article is as amazing.
The clarity for your post is just great and that i can think you’re knowledgeable in this subject.
Fine with your permission allow me to clutch your feed to keep up to date
with coming near near post. Thanks 1,000,000 and please continue
the rewarding work.
Hello very cool site!! Man .. Excellent .. Superb ..
I will bookmark your blog and take the feeds additionally?
I’m glad to search out so many helpful information here in the put up, we need work out extra strategies in this
regard, thank you for sharing. . . . . .
Hey there are using Wordpress for your blog platform?
I’m new to the blog world but I’m trying to get started and
create my own. Do you need any coding expertise to make your own blog?
Any help would be really appreciated!
Here is my webpage … tracfone
I visited various sites except the audio quality for
audio songs present at this website is actually excellent.
Hi there all, here every person is sharing these kinds of knowledge, so it’s good to read this website,
and I used to visit this webpage every day.
Your way of describing all in this paragraph is in fact pleasant, all
be able to easily be aware of it, Thanks a lot.
It’s remarkable to pay a visit this site and reading the
views of all friends concerning this post, while I am also eager
of getting experience.
Stop by my web page :: 2022