Can new fields be added to the WordPress User Profile admin panel within an existing fieldset?
It's easy enough to add new fields to the User Profile by hooking onto
the show_user_profile
and edit_user_profile
actions,
and plenty of tutorials are available online as to how to add a new field to the
bottom of this page using those.
However, I was hoping to be able to add new fields to the "About Yourself" section instead of in its own fieldset.
The only answer I could find on Stack Exchange as to how to do this was a very hacky approach that could easily fall over on a core WordPress upgrade, whilst ChatGPT didn't understand the question and confidently churned out the standard information as to how to add a new field to the bottom of the page.
To find out more if there is a good practice way of adding
fields here, I took a look at how that page is being generated
in the core WordPress codebase. You can find the code under \wp-admin\user-edit.php
.
Unfortunately, inspecting this code shows that the entire form is generated in one big chunk of PHP,
rather than as individual objects or any sort of format that we
might be able to re-order. The action we call via
do_action( 'show_user_profile', $profile_user );
appears below all
the major sections of the page, between Application Password and Additional
Capabilities. This is why new fields always appear here on the admin panel.
As such, the only options available appear to be something hacky, such as adding some JavaScript and/or CSS to re-order the content on-load, or over-elaborate (eg override the entire page generation process). Neither of these approaches are sensible since a WordPress update could easily cause problems. This risk did not outweigh the UX benefit for my personal use case.
This seems another example of where WordPress can be quick and simple to get the basics in place but does not have the framework required for more complex bespoke functionality.