Last active
June 2, 2020 01:03
-
-
Save petertwise/8ebb6a76f018494fcc62171d622cc85f to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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