Hide wordpress field if data is empty in post!

I’m using this code to show my field:

<?php echo '@ ' . get_post_meta(get_the_ID(), 'Author:', true); ?>

When I add a field in my posts it shows it with no problem but for posts that I don’t add any fields it shows “@”.
What I can do to not show anything if field is empty in a post?
Examples: field with datafield with no data [Warning: Both links are NSFW +18]

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can just make a simple check, to see if you have this meta

$author = get_post_meta(get_the_ID(), 'Author:', true);

if ( $author ) :
    echo '@ ' . $author;
endif;


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x