Home › Forums › Add-ons › Flexible Content Field › Echo nothing if value is X › Reply To: Echo nothing if value is X
You modification is causing the error, it should be (note the double ==)
if (get_field('jumbotron_horizontal_alignment') == 'Centre') {
echo 'd-flex text-center justify-content-center';
}
I’m not sure, did you get it working. In my original reply I was just saying that you need to use get_field()
instead of the_field()
and add conditional blocks of code. The exact way these are added will depend on what you want to achieve, but given what you supplied in the op the best I could do was a simple example.
Looking at this
<div class="col-md-12 cxt-title <?php
// if "centre" radio selected, use relevant bootstrap 4 classes
if( get_sub_field('jumbotron_horizontal_alignment') == 'Centre' ):
echo 'd-flex text-center justify-content-center';
elseif( get_sub_field('jumbotron_horizontal_alignment') == 'Left' ):
echo '';
endif;
?>">
it does appear the you have the basic idea. You can probably clean it up a bit and make it easier to read by getting the sub field just once and then using that value in your if statements
$halign = get_sub_field(jumbotron_horizontal_alignment);
if ($halign == 'left') { .....
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.