Support

Account

Home Forums Backend Issues (wp-admin) Hide Div Filed

Solving

Hide Div Filed

  • I am currently using this code:

    <div class = “class2”>
    <? php the_sub_field (‘filed2’); ?>
    </div>
    <div class = “class1”>
    <? php the_sub_field (‘filed1’); ?>
    </div>

    Each has a different class, but both options are available. I want to make a condition. If filed2 is used then class 2 And if filed 1 is used then class 1

    How to cancel the effect of the other class, if it is empty?

  • 
    if (get_sub_field('field2')) {
      ?><div class="class2"><?php the_sub_field('field2'); ?></div><?php 
    } elseif (get_sub_field('field1')) {
      ?><div class="class1"><?php the_sub_field('field1'); ?></div><?php 
    }
    
  • “There has been a critical error on your website.”
    This is the error message that appears on the page after this update.

  • “There has been a critical error on your website.”
    This is the error message that appears on the page after this update.

  • There is one section.

    I have 2 different fields.
    Only one of them appears in section at a time.

    Each of the fields has a different design, in style css class.
    filed1 with style class1
    filed 2 with style class2

    In the page code, an empty div is created with a Class of the unused field.

    The styling of other field (which is different as stated) appears anyway (because we entered an empty DIV code with STYLE CSS.

    How to remove the empty Div and Class?

  • You need to check that the field has a value before outputting the div as my code above shows.

    I do not know why you got an error when you tried it, I do not see anything wrong with the code, but that does not mean I’m not missing the mistake.

    https://codex.wordpress.org/WP_DEBUG

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Hide Div Filed’ is closed to new replies.