Skip to content

Instantly share code, notes, and snippets.

@coulterpeterson
Created January 12, 2024 20:03
Show Gist options
  • Save coulterpeterson/20a9a0cf3863f4cfc794e72fc8e4ea7b to your computer and use it in GitHub Desktop.
Save coulterpeterson/20a9a0cf3863f4cfc794e72fc8e4ea7b to your computer and use it in GitHub Desktop.
Make Gravity Forms support <a> tags in field labels
// 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("&lt;a") ) {
labelContent = labelContent.replace("&lt;a", "<a");
labelContent = labelContent.replace("&lt;/a&gt;", "</a>");
labelContent = labelContent.replace("&gt;", ">");
}
// 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