If the file you want to attach (eg. footer-registered-include.php
) print/display some text, this text will be displayed in the time you include the file.
To assign to the variable the content displayed by the included file you should:
- turn on output buffering
- include file
- contents of the output buffer and end output buffering
function wpdev_before_after($content)
{
if ( is_user_logged_in() && is_front_page() )
{
ob_start();
require_once( get_stylesheet_directory() . '/includes/hero-registered-include.php' );
$beforecontent = ob_get_contents();
ob_clean();
// -- OR --
// $beforecontent = ob_get_clean();
// ob_start();
include_once( get_stylesheet_directory() . '/includes/footer-registered-include.php' );
$aftercontent = ob_get_clean();
$fullcontent = $beforecontent . $content . $aftercontent;
}
// else {
// ...
// }
return $fullcontent;
}
add_filter('the_content', 'wpdev_before_after');
References: