另一种选择是使用the_content
与某种解析器一起过滤,例如PHPDOMDocument, 删除不必要的标记。
伪代码:
function parse_my_content($html) {
$phpdom = new \\DOMDocument;
$phpdom->loadHTML($html);
// do some parser magic ....
$result = $phpdom->saveHTML();
return $result;
}
add_filter(\'the_content\', \'parse_my_content\', 11, 1);
// if you do not want to save it to database, fires on each adding/editing the post
add_filter(\'wp_insert_post\', function($post_arr) {
$post_arr->content = parse_my_content($post_arr);
return $post_arr;
});