filters - I can not include page to wordpress function add_filter, the_content

Wordpress Function add_filter I want to include extra page, on add_filter How can I correct this ?Thanks in Advance !fu

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
Add a comment  | 

1 Answer 1

Reset to default 0

I 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

相关推荐

  • filters - I can not include page to wordpress function add_filter, the_content

    Wordpress Function add_filter I want to include extra page, on add_filter How can I correct this ?Thanks in Advance !fu

    20小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信