• Resolved Pat K

    (@blackcapdesign)


    First – thanks Mr. Wolf for sharing your most excellent collapse-o-matic plugin!

    This is not a support request; rather a solution to a problem reported a few months ago here: https://www.ads-software.com/support/topic/trying-to-use-highlanders-on-img-roll-your-own-and-wordpress-wont-save-it/.

    I added 2 roll-your-own collapse-o-matic blocks on a page. The two triggers were in separate span tags and targeted two separate divs. I used the highlander method to prevent more than one block from being open at a time. It worked great.

    BUT, as soon as I switched out of Text(HTML) mode into Visual mode, the visual editor (TinyMCE) stripped the rel=”uniqueword-highlander” attributes from the span tags.

    (NOTE: it’s probably worth pointing out that I’m NOT using shortcodes to do this, rather just HTML.)

    I ran a bunch of tests and determined that it was TinyMCE stripping out the “rel” attributes (and stripping the values from the title attribute if present). I did a fresh install of WordPress to test and verify this – with zero plugins, using the Twenty Seventeen theme. As soon as I switch from Visual to Text(HTML), the “rel” attributes are stripped from the HTML.

    The solution (reference: https://www.engfers.com/2008/10/16/how-to-allow-stripped-element-attributes-in-wordpress-tinymce-editor/) – a custom function for the child theme functions.php file, which sets the allowed attributes for the container (in this case, a span tag):

    function custom_mce_options( $init ) {
        // Command separated string of extended elements
        $ext = 'span[id|title|class|style|rel]';
    
        // Add to extended_valid_elements if it already exists
        if ( isset( $init['extended_valid_elements'] ) ) {
            $init['extended_valid_elements'] .= ',' . $ext;
        } else {
            $init['extended_valid_elements'] = $ext;
        }
    
        // Super important: return $init!
        return $init;
    }
    
    add_filter('tiny_mce_before_init', 'custom_mce_options');

    Hopefully this helps someone…I’m guessing I am not the only one having this problem.

    Cheers,

    PK

Viewing 1 replies (of 1 total)
  • Plugin Author twinpictures

    (@twinpictures)

    Thank you for sharing this well researched and thoroughly explained solution.
    We just verified that if you switch to Visual mode, all basic HTML, including span and div tags, are in fact stripped.

Viewing 1 replies (of 1 total)
  • The topic ‘A fix for rel attribute being stripped by TinyMCE and breaking highlander’ is closed to new replies.