Skip to content

Instantly share code, notes, and snippets.

@MjHead
Created December 3, 2024 15:45
Show Gist options
  • Save MjHead/1d7bc2f72949b86bd2d923c72b0741e4 to your computer and use it in GitHub Desktop.
Save MjHead/1d7bc2f72949b86bd2d923c72b0741e4 to your computer and use it in GitHub Desktop.
<?php
add_action( 'admin_footer', function() {
?>
<script>
class JetEngineCheckboxSEO {
constructor() {
if ( ! window.rankMathEditor ) {
return;
}
let self = this;
jQuery( document ).on( 'input change', '.cx-checkbox-input', () => {
window.rankMathEditor.refresh( 'content' );
} );
wp.hooks.addFilter( 'rank_math_content', 'jet-engine-checkbox-seo', ( content ) => {
jQuery( '.cx-control-checkbox' ).each( ( groupIndex, groupEl ) => {
let $grEl = jQuery( groupEl );
let selectedItems = [];
$grEl.find( 'input[checked]' ).each( ( itemIndex, itemEl ) => {
selectedItems.push( jQuery( itemEl ).siblings( '.cx-checkbox-label' ).text() );
} );
if ( selectedItems.length ) {
content += '\n' + $grEl.find( '.cx-control__title' ).text() + ': ' + selectedItems.join( ", " );
}
} );
return content;
} );
}
getContent( content ) {
return content;
}
}
window.addEventListener( "load", ( event ) => {
new JetEngineCheckboxSEO();
} );
</script>
<?php
}, 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment