Skip to content

Instantly share code, notes, and snippets.

@petertwise
Last active Jun 2, 2020
Embed
What would you like to do?
Improve Data Entry and Accessibility when WordPress ACF after_title field group area is used. Tab order is now natural and overrides the core WP javascript that moves the focus to the_content after #title.
// Admin Functions
( function( $ ) {
// better accessiblity and data entry for ACF
$(document).ready( function() {
// if there is a an "after_title" field group
if ( $( '#acf_after_title-sortables' ).length ) {
// listen for keydown inside the main title field for any add/edit screen
$('body.post-new-php, body.post-php').on( 'keydown', '#title', function( e ) {
var keyCode = event.keyCode || event.which;
// if the key is tab
if ( 9 == keyCode ) {
// don't do the normal core WP behavior
e.preventDefault();
// find the first field in the after_title area
$( '#acf_after_title-sortables .inside > div:first-child' )
.find( ':input:not([type=hidden])' )
.focus();
}
} );
}
} );
} )( jQuery );
/*
Thanks to these Stack Overflow answers for inspiration:
@neiker - https://stackoverflow.com/a/17150138/947370
@gdoron-is-supporting-monica https://stackoverflow.com/a/11278006/947370
@birgire https://wordpress.stackexchange.com/a/127042/41488
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment