I have a (weird) issue - can't get the ACF field to work on my page. I have a simple text_field
and it shows on the Homepage
page section:
ACF settings:
Lorem ipsum
so it's saved in the databse):
And in my index.php
page I have:
<?php
$hero = the_field('hero_title');
/* tried also */
/* $hero = get_field('text_field'); */
echo '<h1>'.$hero.'</h1>';
?>
Where it shows the blank <h1></h1>
on my page:
What am I doing wrong? I also tried with group
type and I have the same issue.
I have a (weird) issue - can't get the ACF field to work on my page. I have a simple text_field
and it shows on the Homepage
page section:
ACF settings:
Lorem ipsum
so it's saved in the databse):
And in my index.php
page I have:
<?php
$hero = the_field('hero_title');
/* tried also */
/* $hero = get_field('text_field'); */
echo '<h1>'.$hero.'</h1>';
?>
Where it shows the blank <h1></h1>
on my page:
What am I doing wrong? I also tried with group
type and I have the same issue.
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>';
Try
$hero = get_field('hero_title');
Instead of
$hero = the_field('hero_title');