Support

Account

Home Forums Feature Requests Hide content when custom field is empty ?

Solved

Hide content when custom field is empty ?

  • Hi everyone,i have a problem when i use advanced custom field,i use custom field to embed iframe to my video site,with 2 server
    s
    And here my code in theme

    <button class="button" type="button" onClick="document.getElementById('frame').src='<?php the_field('server_1'); ?>'">Openload</button>
    <button class="button" type="button" onClick="document.getElementById('frame').src='<?php the_field('server_2'); ?>'">Openload 2</button>
    <center><iframe name="frame" id="frame" src="<?php the_field('server_1'); ?>" width="640" height="360" scrolling="no" frameborder="0"></iframe></center>

    But problem is,i just use these code for few new posts,and old posts not,so any chance to hide these content if custom field is empty (server 1 and server 2) ? Thank you.

  • 
    if (get_field('server_1')) {
    ?>
    <button class="button" type="button" onClick="document.getElementById('frame').src='<?php the_field('server_1'); ?>'">Openload</button>
    <center><iframe name="frame" id="frame" src="<?php the_field('server_1'); ?>" width="640" height="360" scrolling="no" frameborder="0"></iframe></center>
    <?php 
    }
    
  • Thank you..at first it didnt work,after i googled,i found i missing <php code
    here

    <?php if( get_field('server_1') ): ?>
    <button class="button" type="button" onClick="document.getElementById('frame').src='<?php the_field('server_1'); ?>'">Openload</button>
    <center><iframe name="frame" id="frame" src="<?php the_field('server_1'); ?>" width="640" height="360" scrolling="no" frameborder="0"></iframe></center>
    <?php endif; ?>
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Hide content when custom field is empty ?’ is closed to new replies.