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
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

本文标签: filtersI can not include page to wordpress function addfilterthecontent