Remove Positive Tabindex Values From Content
Removes tabindex values greater than zero from links and fields in post content, which otherwise force a confusing keyboard order, while keeping tabindex 0 and -1.
Opens WPIDE on
Code
add_filter( 'the_content', function ( $content ) {
if ( false === stripos( $content, 'tabindex' ) || ! class_exists( 'WP_HTML_Tag_Processor' ) ) {
return $content;
}
$tags = new WP_HTML_Tag_Processor( $content );
while ( $tags->next_tag() ) {
$value = $tags->get_attribute( 'tabindex' );
if ( null !== $value && (int) $value > 0 ) {
$tags->set_attribute( 'tabindex', '0' );
}
}
return $tags->get_updated_html();
}, 20 );
Notes
Theme and plugin markup outside the post content is not changed.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.