How to display a custom field if there is a data in custom field?

Date: May 10th, 2020
Category: Questions, 170 Views

Asked by: Maddie Bonsey, Location: California

Hi Manish,

I am creating one WordPress theme from scratch, it’s for a law firm.

I created one custom field by enabling ‘custom field’ from ‘screen options’. My field name is ‘url’.

How to display my field value in UI?

How to make this field visible, only if there is a value written in backend?

I did a lot of research and unfortunately didn’t find any answer. Please help!


Answer

Hey Maddie,

You are doing a great work.

Paste the following codes in your UI, where you want to display  your desired ‘custom field’.

							
//use post meta value to display input field, wherever it's required <?php $custom = get_post_meta($post->ID, 'url', true); if ($custom) { ?> <a href="<?php echo get_post_meta($post->ID, 'url', true); ?>">custom text</a> <?php } else { // do nothing; } ?>
Share my post: 

One response to “How to display a custom field if there is a data in custom field?”

Leave a Reply

Your email address will not be published. Required fields are marked *