the_field()
function shows the value and it doesn’t get/return anything. Like the_title()
and other template tags starting with the_
.
It means that:
This line prints the value and $hero
variable is empty.
$hero = the_field('hero_title');
This line prints only <h1>
tags.
echo '<h1>'.$hero.'</h1>';
What you want is:
echo '<h1>' . get_field('hero_title') . '</h1>';