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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745301039a4621435.html
评论列表(0条)