I want to echo this title variable inside the h1 tag, but I get an error message. Can you please tell me what I'm doing wrong?
<?php
$title = get_field ('page_title');
if ($title):
<h1> echo ($title); </h1>
endif;
?>
I want to echo this title variable inside the h1 tag, but I get an error message. Can you please tell me what I'm doing wrong?
<?php
$title = get_field ('page_title');
if ($title):
<h1> echo ($title); </h1>
endif;
?>
This line is wrong:
<h1> echo ($title); </h1>
PHP won't understand the HTML tags so it complains about them.
There are a couple of ways you might do this, but I'd suggest replacing the entire line with
echo "<h1>$title</h1>";
PHP will insert the current value of $title in the string and echo the result.
Reference: PHP double-quoted Strings