Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save SteveJonesDev/be53c109c62fcd2f57b8566800a40339 to your computer and use it in GitHub Desktop.

Select an option

Save SteveJonesDev/be53c109c62fcd2f57b8566800a40339 to your computer and use it in GitHub Desktop.
WordPress Oxygen page builder: Move title attribute to iframe
(function () {
function fixOxygenVideoTitles() {
document.querySelectorAll( '.ct-video[title]' ).forEach( function ( wrapper ) {
const iframe = wrapper.querySelector( 'iframe' );
const title = wrapper.getAttribute( 'title' );
if ( iframe && title && ! iframe.getAttribute( 'title' ) ) {
iframe.setAttribute( 'title', title );
wrapper.removeAttribute( 'title' );
}
} );
}
function init() {
fixOxygenVideoTitles();
const observer = new MutationObserver( fixOxygenVideoTitles );
observer.observe( document.body, {
childList: true,
subtree: true,
} );
}
if ( document.readyState === 'loading' ) {
document.addEventListener( 'DOMContentLoaded', init );
} else {
init();
}
window.addEventListener( 'load', fixOxygenVideoTitles );
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment