Support

Account

Home Forums General Issues PHP apprendice

Solved

PHP apprendice

  • Hello,

    I’ve been adding this code to my site and I would like to do some improvements.

    if(get_field('apelativo'))
    {
    	 _e('Apelativo: ','csc-themewp: '); the_field('apelativo');
    }
      
    ?><br/>
    <?php 
    
    if(get_field('profundidad'))
    {
    	 _e('Profundidad: ','csc-themewp: '); the_field('profundidad');
    }
      
    ?><br/>
    <?php 
    
    if(get_field('hundimiento'))
    {
    	 _e('Año hundimiento: ','csc-themewp: '); the_field('hundimiento');
    }
      
    ?><br/> 
    <?php 

    So when the get_field is null it won’t show up on the website.. but will leave the blank space… how do I delete this blank space?

    I’ve never develop before.. and I’m sure that you will find and easy solution for that!

    Thanks so much!

  • I assume by “blank space” you’re referring to the line break (<br />). Easy fix. Just include the break inside the if so that it will only render if the field is not null.

    Example:

    <?php
      if (get_field('apelativo')) {
        _e('Apelativo: ','csc-themewp: '); the_field('apelativo');
        echo '<br />';
      }
    ?>
  • Thanks kaitlyn! It’s the first time that I do any developing.. and I’m a bit lost…
    Thanks a lot!

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

The topic ‘PHP apprendice’ is closed to new replies.