最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to disable TinyMCE from removing span tags

programmeradmin1浏览0评论

I am posting Word generated HTML to WordPress via XMLRPC. Before I go to post.php, the format is correctly preserved in the database. TinyMCE performs its magic and I lose quite a few formatting details.
The main issue i am seeing is that <span> tag with style information surrounding other elements are stripped out. I have verified that these tags are indeed removed by TinyMCE and not Kses. Is there a way to prevent TinyMCE from altering the HTML? I have tried

add_filter('tiny_mce_before_init', 'tinymce_init');

function tinymce_init( $init ) {
    $init['extended_valid_elements'] .= ', span[style|id|nam|class|lang]';
$init['verify_html'] = false;
    return $init;
}

which didn't help. According to TinyMCE documentation, "verify_html"

This option enables or disables the element cleanup functionality. If you set this option to false, all element cleanup will be skipped but other cleanup functionality such as URL conversion will still be executed.

I am posting Word generated HTML to WordPress via XMLRPC. Before I go to post.php, the format is correctly preserved in the database. TinyMCE performs its magic and I lose quite a few formatting details.
The main issue i am seeing is that <span> tag with style information surrounding other elements are stripped out. I have verified that these tags are indeed removed by TinyMCE and not Kses. Is there a way to prevent TinyMCE from altering the HTML? I have tried

add_filter('tiny_mce_before_init', 'tinymce_init');

function tinymce_init( $init ) {
    $init['extended_valid_elements'] .= ', span[style|id|nam|class|lang]';
$init['verify_html'] = false;
    return $init;
}

which didn't help. According to TinyMCE documentation, "verify_html"

This option enables or disables the element cleanup functionality. If you set this option to false, all element cleanup will be skipped but other cleanup functionality such as URL conversion will still be executed.

Share Improve this question edited May 22, 2012 at 22:47 ltfishie asked May 18, 2012 at 14:47 ltfishieltfishie 7652 gold badges9 silver badges28 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 9

I couldn't find the extended_valid_elements option in the settings panel for TinyMCE advanced, but adding the following to my functions.php solved it:

function override_mce_options($initArray) {
    $opts = '*[*]';
    $initArray['valid_elements'] = $opts;
    $initArray['extended_valid_elements'] = $opts;
    return $initArray;
} add_filter('tiny_mce_before_init', 'override_mce_options');

Source

I almost always use the TinyMCE Advanced plugin - there is an admin page (Settings->TinyMCE Config) that let you add supported tags using the extended_valid_elements option. Simply add span and whatever other tags you don't want removed and enjoy!

If you use TinyMCE Advanced plugin, there is a companion plugin called TinyMCE Advanced Configuration, with which you can change config settings, like extended_valid_elements option.

发布评论

评论列表(0)

  1. 暂无评论