Skip to content

Instantly share code, notes, and snippets.

@MjHead
Created December 3, 2024 15:45

Revisions

  1. MjHead created this gist Dec 3, 2024.
    49 changes: 49 additions & 0 deletions jet-engine-rank-math-checkboxes.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    <?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 );