简体   繁体   中英

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM