WordPress没有“最终输出”过滤器。
只需谷歌搜索,我就从堆栈溢出中找到了一个有趣的答案。
所有学分转到@kfriend
更多详细信息(SO问题链接):Wordpress filter to modify final html output
<?php
/**
* Output Buffering
*
* Buffers the entire WP process, capturing the final output for manipulation.
*/
ob_start();
add_action(\'shutdown\', function() {
$final = \'\';
// We\'ll need to get the number of ob levels we\'re in, so that we can iterate over each, collecting
// that buffer\'s output into the final output.
$levels = ob_get_level();
for ($i = 0; $i < $levels; $i++)
{
$final .= ob_get_clean();
}
// Apply any filters to the final output
echo apply_filters(\'final_output\', $final);
}, 0);
挂接到final\\u输出过滤器的示例:
<?php
add_filter(\'final_output\', function($output) {
return str_replace(\'foo\', \'bar\', $output);
});
?>