Wasteland
Wasteland

Reputation: 5379

PHP (WP) - Ignoring HTML markup

Why does the br html tag is ignored in the browser?

<p>
                <?php 
                $footer_1 = the_field('footer_1');
                $footer_2 = the_field('footer_2');
                $footer_3 = the_field('footer_3');
                if (!empty($footer_1)) {
                    the_field('footer_1');
                    echo "<br />";
                }
                if (!empty($footer_2)) {
                    the_field('footer_2');
                    echo "<br />";
                }
                if (!empty($footer_3)) {
                    the_field('footer_3');
                }
                ?>
            </p>

Edit: The browser code outputs the p element as one piece of text. No br tag displayed there either. The three variables are text fields from Advanced Custom Fields.

Upvotes: 0

Views: 89

Answers (1)

Tokant
Tokant

Reputation: 324

the_field is used to actually echo out the custom field data, so you cannot assign it to a variable. Use get_field instead, like so:

<p>
<?php 
$footer_1 = get_field('footer_1');
$footer_2 = get_field('footer_2');
$footer_3 = get_field('footer_3');
if (!empty($footer_1)) {
    echo $footer_1 . '<br>';
}
if (!empty($footer_2)) {
    echo $footer_2 . '<br>';
}
if (!empty($footer_3)) {
    echo $footer_3;
}
?>
</p>

Upvotes: 1

Related Questions