Skip to content

Instantly share code, notes, and snippets.

@askwpgirl
Last active September 21, 2023 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save askwpgirl/f645d8c46a7870f46c547229ede4decf to your computer and use it in GitHub Desktop.
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
// 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