用于修改最终 html 输出的 WordPress 过滤器 [英] WordPress filter to modify final html output

查看:22
本文介绍了用于修改最终 html 输出的 WordPress 过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WordPress 具有强大的过滤器支持,可以获取各种特定的内容位并在输出之前对其进行修改.就像 the_content 过滤器一样,它允许您在将帖子输出到屏幕之前访问该帖子的标记.

WordPress has great filter support for getting at all sorts of specific bits of content and modifying it before output. Like the_content filter, which lets you access the markup for a post before it's output to the screen.

我正在尝试找到一个包罗万象的过滤器,它使我能够在输出之前完全修改最终标记.

I'm trying to find a catch-all filter that gives me one last crack at modifying the final markup in its entirety before output.

我已多次浏览过滤器列表,但没有任何内容让我感到惊讶:https://codex.wordpress.org/Plugin_API/Filter_Reference

I've browsed the list of filters a number of times, but nothing jumps out at me: https://codex.wordpress.org/Plugin_API/Filter_Reference

有人知道吗?

推荐答案

AFAIK,没有钩子,因为主题使用 HTML 不会被 WordPress 处理.

AFAIK, there is no hook for this, since the themes uses HTML which won't be processed by WordPress.

但是,您可以使用输出缓冲来捕获最终的 HTML:

You could, however, use output buffering to catch the final HTML:

<?php
// example from php.net
function callback($buffer) {
  // replace all the apples with oranges
  return (str_replace("apples", "oranges", $buffer));
}
ob_start("callback");
?>
<html><body>
<p>It's like comparing apples to oranges.</p>
</body></html>
<?php ob_end_flush(); ?>
/* output:
   <html><body>
   <p>It's like comparing oranges to oranges.</p>
   </body></html>
*/

这篇关于用于修改最终 html 输出的 WordPress 过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆