How to prevent WordPress 3.9 / TinyMCE 4 from stripping <style> tags?

Up until WP 3.9 I could specify inline Stylesheets using <style> tags in WP’s “Text” tab, which would survive switching to WYSIWYG.

From WP 3.9, TinyMCE will strip <style> tags upon switching to WYSIWYG.

Read More

I’ve tried the following as MU plugin, but it doesn’t help:

add_filter('tiny_mce_before_init', 'vsl2014_filter_tiny_mce_before_init');
function vsl2014_filter_tiny_mce_before_init( $options ) {

    if ( ! isset( $options['extended_valid_elements'] ) )
        $options['extended_valid_elements'] = '';

    $options['extended_valid_elements'] .= ',style';
    return $options;
}

Related posts

Leave a Reply

3 comments

  1. Try specifying valid_children and custom_elements:

    add_filter('tiny_mce_before_init', 'vsl2014_filter_tiny_mce_before_init');
    function vsl2014_filter_tiny_mce_before_init( $options ) {
    
        if ( ! isset( $options['extended_valid_elements'] ) ) {
            $options['extended_valid_elements'] = 'style';
        } else {
            $options['extended_valid_elements'] .= ',style';
        }
    
        if ( ! isset( $options['valid_children'] ) ) {
            $options['valid_children'] = '+body[style]';
        } else {
            $options['valid_children'] .= ',+body[style]';
        }
    
        if ( ! isset( $options['custom_elements'] ) ) {
            $options['custom_elements'] = 'style';
        } else {
            $options['custom_elements'] .= ',style';
        }
    
        return $options;
    }