Support

Account

Home Forums General Issues Page Link custom field – do not display if NULL

Solved

Page Link custom field – do not display if NULL

  • I have set up a page link custom field on my posts. This is not required for all posts and I have allowed ‘null’ values.

    If this is the code to display page link fields:

    <a href="<?php the_field('page_link'); ?>">Read this!</a>

    What would the if statement be so that it doesn’t display anything if the field is null?

  • 
    <?php if( get_field('page_link') ): ?>
    	<a href="<?php the_field('page_link'); ?>">Read this!</a>
    <?php endif; ?>
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Page Link custom field – do not display if NULL’ is closed to new replies.