Before & After Content – After Content directly below Before Content when using require_once

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:

  1. turn on output buffering
  2. include file
  3. 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: