You cannot include
template files via URL, which is what get_template_directory_uri()
returns. You need to use the server file path, which you get get with get_theme_file_path()
:
$heroslider = get_theme_file_path( 'template-parts/hero-slider.php' );
echo $heroslider;
include_once( $heroslider );
However, if you’re including templates (rather than files with function/class definitions), you should use get_template_part()
to get the correct path and include it in one go (just leave out the file extension):
get_template_part( 'template-parts/hero-slider' );