admin管理员组文章数量:1419242
Wordpress Function add_filter
I want to include extra page, on add_filter How can I correct this ?
Thanks in Advance !
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');
Wordpress Function add_filter
I want to include extra page, on add_filter How can I correct this ?
Thanks in Advance !
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');Share Improve this question edited Jul 23, 2019 at 21:06 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Jul 23, 2019 at 19:21 Abhijeet ShindeAbhijeet Shinde 214 bronze badges 2
- Why do you want to add new page like that, do you mind posting some additional details about what you want to achieve in here? – Kumar Commented Jul 24, 2019 at 11:38
- I am creating dynamic content of custom plugin. Thank you. – Abhijeet Shinde Commented Jul 24, 2019 at 16:31
1 Answer
Reset to default 0I think the problem is that the PHP include()
function will output instead of return data. What you can do is output buffer the include which would look something like:
// 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();
Additionally, you may want to look into get_template_part()
instead of include. For more information regarding output buffering please review the PHP docs:
https://www.php/manual/en/ref.outcontrol.php
本文标签: filtersI can not include page to wordpress function addfilterthecontent
版权声明:本文标题:filters - I can not include page to wordpress function add_filter, the_content 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745301039a2652371.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论