Sandeep Kumar Mishra
Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.
When you’re working with WordPress customizations, hooks are your best friend. Trust me, as an Indian developer who’s spent countless hours tweaking WordPress sites, I can vouch for their power. One such hook is the edit_user_profile filter. This hook is fired after the ‘About the User’ settings table on the ‘Edit User’ screen. To use it, you’ll need to register it with add_filter. You can pop this code into your theme’s functions.php file or, ideally, in a custom WordPress plugin to ensure your modifications remain intact even after theme updates.
Here’s how you can add a birthday field to the user profile form:
function weplugins_userMetaBirthdayForm(WP_User $user) {
?>
<h2>Birthday</h2>
<table class="form-table">
<tr>
<th><label for="user_birthday">Birthday</label></th>
<td>
<input
type="date"
value="<?php echo esc_attr(get_user_meta($user->ID, 'birthday', true)); ?>"
/>
</td>
</tr>
</table>
<?php
}
add_action('edit_user_profile', 'weplugins_userMetaBirthdayForm');
Here’s an example of modifying user profile defaults:
function weplugins_modify_edit_user_profile_defaults($profile_user) {
// Update the $profile_user variable according to your requirements.
return $profile_user;
}
// add the filter
add_filter("edit_user_profile", "weplugins_modify_edit_user_profile_defaults", 10, 1);
If you ever need to remove a hook callback, follow this example:
remove_filter("edit_user_profile", "weplugins_modify_edit_user_profile_defaults", 10, 1);
Ensure you provide the same callback function name, priority, and number of arguments to successfully remove the hook.
If you need help with customization or have any questions, feel free to Contact Us. We’d be happy to assist you!
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.