我想在TinyMCE编辑器中使用HTML(schema.org)。我在我的custom.php
// Prevent TinyMCE from stripping out schema.org metadata
function schema_TinyMCE_init($in)
{
/**
* Edit extended_valid_elements as needed. For syntax, see
* http://www.tinymce.com/wiki.php/Configuration:valid_elements
*
* NOTE: Adding an element to extended_valid_elements will cause TinyMCE to ignore
* default attributes for that element.
* Eg. a[title] would remove href unless included in new rule: a[title|href]
*/
if(!empty($in[\'extended_valid_elements\']))
$in[\'extended_valid_elements\'] .= \',\';
$in[\'extended_valid_elements\'] .= \'@[id|class|style|title|itemscope|itemtype|itemprop|datetime|rel],div,dl,ul,dt,dd,li,span,meta,content,a|rev|charset|href|lang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur],div[*],meta[*],span[*],meta[itemprop],meta[content]\';
return $in;
}
add_filter(\'tiny_mce_before_init\', \'schema_TinyMCE_init\' );
该代码适用于某些元素,如
<span itemprop="name">
但也不是为了
<meta itemprop="uploadDate" content="2015-12-15T10:10:04.000Z"/>
为什么它不适用于meta itemprop="..." content="..."
最合适的回答,由SO网友:Dave Romsey 整理而成
我找到了这个解决方案meta
到valid_children
(未测试):
// Prevent TinyMCE from stripping out schema.org metadata
// https://snipt.net/jamesw/prevent-tinymce-from-stripping-schemaorg-attributes-in-wordpress/
function schema_TinyMCE_init( $in ) {
/**
* Edit extended_valid_elements as needed. For syntax, see
* http://www.tinymce.com/wiki.php/Configuration:valid_elements
*
* NOTE: Adding an element to extended_valid_elements will cause TinyMCE to ignore
* default attributes for that element.
* Eg. a[title] would remove href unless included in new rule: a[title|href]
*/
if ( ! empty( $in[\'extended_valid_elements\'] ) ) {
$in[\'extended_valid_elements\'] .= \',\';
}
$in[\'extended_valid_elements\'] .= \'@[id|class|style|title|itemscope|itemtype|itemprop|datetime|rel],div,dl,ul,dt,dd,li,span,meta[!content],a|rev|charset|href|lang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur]\',
if ( !empty( $in[\'valid_children\'] ) ) {
$in[\'valid_children\'] .= \',\';
}
$in[\'valid_children\'] .= \'+body[meta],+div[meta]\';
return $in;
}
add_filter(\'tiny_mce_before_init\', \'schema_TinyMCE_init\' );