Skip to content Skip to sidebar Skip to footer

Insert Html In If Statement

How do I insert HTML code where it says 'do something'? When r

Solution 1:

Close and open the PHP blocks, like this:

if(get_field('member_only_content')){
?>
    <html></html><?php
} else{
?><html></html><?php
}

You can also use PHP's alternative syntax for this:

if(get_field('member_only_content')): ?>
    <html></html><?phpelse: ?><html></html><?phpendif;

Solution 2:

Like this!

<?phpif(get_field('member_only_content')) : ?><div>Html stuff</div><?phpelse : ?><div>More Html stuff</div><?phpendif;

Solution 3:

Put HTML in place of the string.

<?phpif(get_field('member_only_content')){
    echo"<your>HTML here</your>";
}else{
    echo"<other>HTML</other>";
}
?>

You can also break out of the PHP tags

<?phpif(get_field('member_only_content')){
    ?><your>HTML here</your><?
}else{

    ?><other>HTML</other><?
}
     ?>

Solution 4:

That would be because you placed the HTML code within php tags (<?php ?>). Text inside this tag is interpreted as a PHP instruction, thus it won't render HTML. There are 2 general ways render the HTML in a PHP file:

Echo the HTML

<?phpif (get_field ('member_only_content')) {
        echo"<span>Put HTML here</span>";
    }
    else {
        echo"<span>Put HTML here</span>";
    }
?>

Place the HTML Outside PHP Tags

<?phpif (get_field ('member_only_content')): ?><span>Put HTML here</span><?phpelse: ?><span>Put HTML here</span><?phpendif;?>

Solution 5:

Or you can use the <<< statement:

echo <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END;

Straight from http://php.net/manual/en/function.echo.php

Post a Comment for "Insert Html In If Statement"