Created
January 12, 2024 20:03
-
-
Save coulterpeterson/20a9a0cf3863f4cfc794e72fc8e4ea7b to your computer and use it in GitHub Desktop.
Make Gravity Forms support <a> tags in field labels
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
// When the page is ready | |
window.addEventListener('load', function () { | |
if (document.querySelector('body') !== null) { | |
let allGfLabels = document.querySelectorAll('.gfield_label'); | |
allGfLabels.forEach(label => { | |
let labelContent = label.innerHTML; | |
// Only start the cascade of replacements if there's definitely an opening HTML tag of that type in the string | |
if( labelContent.includes("<a") ) { | |
labelContent = labelContent.replace("<a", "<a"); | |
labelContent = labelContent.replace("</a>", "</a>"); | |
labelContent = labelContent.replace(">", ">"); | |
} | |
// Note: more HTML tags could be supported by following the pattern above for <a> tags | |
label.innerHTML = labelContent; | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment