允许您的特定<new-page>
元素,您可以添加过滤器,以便WP将其识别为允许的标记:
// Step one - add to the allowed tags
add_action(\'init\', function() {
// Access the global allowed tags array
global $allowedtags;
// Add new-page as an allowed tag
$allowedtags[\'new-page\'] = array();
// If you ever use attributes such as <new-page href="url" title="My Title">
// Then you\'ll need to include those within the array like so:
// $allowedtags[\'new-page\'] = array(\'href\' => array(), \'title\' => array());
});
// Step two - add to allowed tags in TinyMCE (the editor)
add_filter(\'tiny_mce_before_init\', function($a) {
$a[\'extended_valid_elements\'] = \'new-page\';
// Again if you ever need attributes, you\'ll specify those here
// $a[\'extended_valid_elements\'] = \'new-page[href|title]\';
return $a;
});
因为这段代码是专门为TinyMCE编写的,所以您必须进行测试,以确定它是与块编辑器一起工作,还是仅与Classic一起工作。如果编辑器无法使用它,您还可以选择创建一个短代码或一个块来输出所讨论的标记。