Two questions
I need an updated code for this question
How can I hide the value if there is no value entered?
My value would be a link, and this is my current code
<a href="<?php echo get_post_meta($post->ID, 'mp3_link1', true); ?>" target="_blank">MP3</a>
I need to do this without any plugins.
Two questions
I need an updated code for this question
How can I hide the value if there is no value entered?
My value would be a link, and this is my current code
<a href="<?php echo get_post_meta($post->ID, 'mp3_link1', true); ?>" target="_blank">MP3</a>
I need to do this without any plugins.
Share Improve this question edited Feb 18, 2019 at 21:01 Nathan Johnson 6,5386 gold badges30 silver badges49 bronze badges asked Jan 20, 2019 at 22:42 user159405user159405 1- Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under the CC BY-SA 3.0 license for SE to distribute that content. By SE policy, any vandalism will be reverted. If you want to know more about deleting a post, consider taking a look at: How does deleting work? – iBooot Commented Feb 18, 2019 at 20:47
1 Answer
Reset to default 1All you have to do to hide this link is to check, if it's empty:
<?php if ( $link = get_post_meta($post->ID, 'mp3_link1', true) && trim($link) ) : ?>
<a href="<?php echo esc_attr($link); ?>" target="_blank">MP3</a>
<?php endif; ?>