TinyMCE Advanced
[resolved] Prevent span tags from being removed (9 posts)

  1. jason1111
    Posted 2 years ago #

    Saw several posts that TinyMCE Advanced can extend wordpress so that it doesnt remove the span tags. Just installed the latest and I cant find the option. Supposedly it adds extend_valid_elements to stop the removal of span tags. The post is 2 years old so maybe thats no longer a valid function.


  2. Andrew Ozz
    WordPress Dev
    Plugin Author

    Posted 2 years ago #

    Yeah, currently TinyMCE Advanced doesn't add any extend_valid_elements. That can be added by any WP plugin or theme, the setting is pretty straight-forward: http://www.tinymce.com/wiki.php/Configuration:extended_valid_elements

  3. jason1111
    Posted 2 years ago #

    Thanks Andrew. That was helpful. Took some digging but I found this blog that helped: http://www.engfers.com/2008/10/16/how-to-allow-stripped-element-attributes-in-wordpress-tinymce-editor/

    Here was my solution for anyone else looking to do the same thing.

    function myextensionTinyMCE($init) {
        // Command separated string of extended elements
        $ext = 'span[id|name|class|style]';
        // Add to extended_valid_elements if it alreay 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', 'myextensionTinyMCE' );
  4. Dave
    Posted 1 year ago #

    @jason1111 thanks! This kept me from pulling out my hair every time the client used the visual editor, resulting in all my custom styling being removed.

    Makes no sense why this is not already accounted for. Should be a built-in rule.

  5. Lydia Roberts
    Posted 1 year ago #

    Ditto. That snippet really helped me out, was getting frustrated not being able to use spans in the editor.

  6. wpu9000
    Posted 1 year ago #

    where do I add the above code from @jason1111?
    I put it in functions.php but it had no effect.

    thank you

  7. Dave
    Posted 1 year ago #

    It should work.

    Did you place it in the correct theme directory and if so, where exactly in the file did you place the code?

  8. wpu9000
    Posted 1 year ago #

    I put it at the end of functions.php.

  9. kopf-und-stift
    Posted 1 year ago #

    where must i place the code?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • TinyMCE Advanced
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.