You can add to the end of theme’s header.php
file this:
if( is_single() ) {
global $wp_query;
$wp_query->set_404();
status_header( 404 );
get_template_part( '404' );
exit();
}
Note that the get_template_part( '404' )
function needs 404.php
file in your theme directory.