1

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');
  • 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 Jul 24 '19 at 11:38
  • I am creating dynamic content of custom plugin. Thank you. – Abhijeet Shinde Jul 24 '19 at 16:31
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.net/manual/en/ref.outcontrol.php

|improve this answer|||||
  • Hello, Thank you so much for support... Now It's working... – Abhijeet Shinde Jul 24 '19 at 16:21
  • @AbhijeetShinde Fantastic! If you've found this answer helpful please upvote to show other readers that this is a possible solution. If it ended up solving your problem completely you can click the checkmark to show future readers that this answer solved your problem. – Howdy_McGee Jul 24 '19 at 16:25
  • Howdy_McGee ! Thank you, I have voted, Can you try to answer one more question about redirecting page issue - Here is a question - wordpress.stackexchange.com/questions/343603/… – Abhijeet Shinde Jul 24 '19 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.