Last active
September 21, 2023 03:08
-
-
Save askwpgirl/f645d8c46a7870f46c547229ede4decf to your computer and use it in GitHub Desktop.
Disable Links for Keyboard Navigation and Screen Readers on Elementor Post Widget Image
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
// Add this to Code Snippets plugin Javascript snippet | |
// This sets tabindex to -1 so that keyboard navigation skips over the image link | |
jQuery(document).ready(function () { | |
setTabindex('.elementor-post__thumbnail__link', '-1') | |
function setTabindex(selector, tabindex) { | |
var links = jQuery(selector); | |
for (var i = 0, j = links.length; i < j; i++) { | |
links[i].setAttribute('tabindex', String(tabindex)); | |
} | |
} | |
// This sets the aria-hidden attribute to true so screenreaders don't read the image link | |
setAriahidden('.elementor-post__thumbnail__link', 'true') | |
function setAriahidden(selector, aria) { | |
var links = jQuery(selector); | |
for (var i = 0, j = links.length; i < j; i++) { | |
links[i].setAttribute('aria-hidden', String(aria)); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment