0

In cases i want to add individual styles for an element its easy i just add inline styles inside p tags, because _wp_add_global_attributes has style attribute....

but when i want to add tag itslef to target/select multiple elements TinyMCE editor removes it entirely... so I got inside core and found filter tiny_mce_before_init but i don't know how to add style tag to allowed tags array!!!!!!!

1

There are some things to try in this stackoverflow thread. The one I'm trying:

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;
}
0

Starting with version 4.9 there is no real reason to do that, just use the costumizer to add CSS rules that will match your needs.

The more proper solution is to use a template which are supported for all CPTs since 4.5 IIRC, or add the CSS conditionally with code hooking on the wp_head action.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.