On the Edit User page in the back end, how can I hook into the text area labelled Biographical Info which contains the description field? I'd like to change the <textarea>
rows value from the default of 5
to 15
?
1 Answer
Unfortunately there is no hook available to modify the HTML for the description field on the edit user page. The output is hard-coded.
One workaround is to use CSS to set a minimum height for the text area. I think this is the best approach.
add_action( 'admin_print_styles-profile.php', 'wpse_user_description_css' );
add_action( 'admin_print_styles-user-edit.php', 'wpse_user_description_css' );
function wpse_user_description_css() { ?>
<style>
.profile-php #description,
.user-edit-php #description {
min-height: 291px;
}
</style>
<?php
}
Alternatively, we could use JavaScript to set the value of rows
to 15
:
add_action( 'admin_footer-profile.php', 'wpse_user_description_js' );
add_action( 'admin_footer-user-edit.php', 'wpse_user_description_js' );
function wpse_user_description_js() { ?>
<script>
var description_box = document.querySelector( "#description" );
if ( description_box ) {
description_box.setAttribute( "rows", "15" );
}
</script>
<?php
}
It would also be technically possible to capture the final output of all of the HTML for the page, then parse and modify it, but that's way overkill for something like this.
-
1The solution works only when the user screen is "profile.php" (eg. current logged-in user). Other users' current screen is "user-edit.php". Adding
&& 'user-edit' !== $screen->id )
seems to give the required conditionality when assessing the get_current_screen() output. Jul 7, 2017 at 7:49 -
My bad! Yeah, I forgot that the screen id is changed based on the context of the user being viewed. I've updated the solutions accordingly. Jul 7, 2017 at 8:04
-
1There are also available the actions:
admin_footer-profile.php
,admin_footer-user-edit.php
and alsoadmin_print_styles-profile.php
,admin_print_styles-user-edit.php
. We could also restrict CSS selectors with the similar body classes. I like your non-jquery dependency in your javascript ;-)– birgireJul 7, 2017 at 9:02 -
1