【问题标题】:regex delete html comments in wordpress正则表达式删除wordpress中的html评论
【发布时间】:2011-07-21 10:03:57
【问题描述】:

如何删除wordpress中</html>标签后的所有cmets?

例子

</body></html> <!-- bla bla --><!-- more bla bla --><!--and more bla bla -->

替换

</body></html>

我希望将一个函数包含在我的 function.php 主题中。

谢谢

标签: php html-parsing


【解决方案1】:

我发现了这个:

如果你把它放在你的functions.php中,它会删除你代码中的所有HTML cmets。

function callback($buffer) {
    $buffer = preg_replace('/<!--(.|s)*?-->/', '', $buffer);
    return $buffer;
}
function buffer_start() {
    ob_start("callback");
}
function buffer_end() {
    ob_end_flush();
}
add_action('get_header', 'buffer_start');
add_action('wp_footer', 'buffer_end');

【讨论】:

  • 解释得好一点。 :)
猜你喜欢
  • 2015-04-09
  • 1970-01-01
  • 1970-01-01
  • 2017-08-04
  • 2017-01-10
  • 1970-01-01
  • 1970-01-01
  • 2010-10-20
  • 2012-02-02
相关资源
最近更新 更多