March 8, 2012
Simple php if !empty-function
Question by Jörg Mayer
I want to simply echo a link (set in a custom field in WordPress), when the corresponding field is not empty.
I tried the following, but the output is missing the link. Only the field as plain text gets printed
<?php $projekt_link = the_field('link');
if(!empty($projekt_link)){
echo '<a href="'.$projekt_link->name.'" class="button">Zum Projekt</a>';
}
?>
Answer by Starx
If you are using the Advance Custom Fields
plugin, then the correct syntax is
$projekt_link = get_field('link');