您可以通过在“functions.php”中创建自定义函数来解决此问题:
function indented_wp_head(){
ob_start();
wp_head();
$header = ob_get_contents();
ob_end_clean();
echo preg_replace("/\\n/", "\\n\\t", substr($header, 0, -1));
echo "\\n";
}
现在只需在“header.php”中调用此函数:
<head>
<!-- ... -->
<?php indented_wp_head() ?>
</head>
如果你想用它
wp_footer()
您也可以在“functions.php”中创建此函数以供一般使用:
/**
* Indents the output of
* a function
*
* @return void
*/
if (! function_exists("print_indented")) {
function print_indented($fn)
{
ob_start();
call_user_func($fn);
$html = ob_get_contents();
ob_end_clean();
echo preg_replace("/\\n/", "\\n\\t", substr($html, 0, - 1));
echo "\\n";
}
}
并在“header.php”或“footer.php”中调用它,如
<?php print_indented("wp_footer") ?>
<?php print_indented("wp_head") ?>