Wordpress Function add_filter
我想在add\\u filter上添加额外页面,如何更正<提前谢谢!
function page_content($content) {
global $post;
if ( is_object( $post ) && $post->ID == 134 ) {
if(is_page()) {
$extra_content = \' This is my extra content\';
$content .= $extra_content;
$content .= include(\'horo-header.php\');
}
return $content;
}
}
add_filter(\'the_content\', \'page_content\');
最合适的回答,由SO网友:Howdy_McGee 整理而成
我认为问题在于PHPinclude()
函数将输出而不是返回数据。您可以做的是输出缓冲区include,它看起来像:
// Start buffering any output
ob_start();
// Output the include into the buffer.
include( \'horo-header.php\' );
// Append the buffered output into the $content variable
$content .= ob_get_clean();
此外,您可能需要研究
get_template_part()
而不是包含。有关输出缓冲的更多信息,请查看PHP文档:
https://www.php.net/manual/en/ref.outcontrol.php