Since you’re in a Loop, you don’t need to grab the post ID or use get_the_title()
. Instead, replace line 2 and 3 of your code with:
the_title('<h1>', '</h1>');
Or, if you want to include a link as well:
<h1><a href="https://wordpress.stackexchange.com/questions/272948/<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>