You can use wp_register_script()
then wp_enqueue_script()
to inject javascript into wp admin.
functions.php or plugin (my personal recc would be a simple plugin):
wp_register_script( 'focus-tag-name-script', 'path/to/script.js' , 10 );
wp_enqueue_script( 'focus-tag-name-script' );
script:
jQuery( window ).on( 'load', function() {
jQuery( 'input[name="tag-name"]' )
.focus() // place cursor in field
.select(); // select field contents
} );
As requested in the comments, here it is as a plugin:
(I just wrote this out here without testing, but at the very least should put you in the right direction if there are any errors)
// define the plugin
jQuery( function( $ ) {
$.fn.fieldFocus = function( options ) {
var settings = $.extend({
select: false
}, options );
this.focus() // place cursor in field
if ( settings.selectContents ) this.select(); // select field contents
} );
} );
// calling the plugin
jQuery( window ).on( 'load', function() {
// places cursor in the field
jQuery( 'input[name="tag-name"]' ).fieldFocus();
// places cursor in the field and selects contents
jQuery( 'input[name="tag-name"]' ).fieldFocus( {
selectContents: true
} );
}