My code is as below:
<?php
if( get_field( "facebook" ) !== '' ): ?>
<a href="<?php echo the_field('facebook'); ?>">Facebook</a>
<?php endif;?>
Instead of echoing the field's value which is (wwww.facebook.com), it's echoing it relative to the wordpress website.
Also, is my code efficient? Or is there a simpler way to do it?
Edit: What finally worked for me:
<?php
$website = (get_field('website'));
if(!empty($website)){
$final_url = (!preg_match("~^(?:f|ht)tps?://~i", $website))? 'http://'.$website: $website;
echo "<a href=\"$final_url\">$final_url</a>" . "<br />";
}
?>
tag only if the custom field is processed. Otherwise, to skip to the next argument. – May 03 '13 at 19:54
to follow the tag? just look at my new edit then – reikyoushin May 03 '13 at 19:55
tag regardless of whether the field is there or not. I'd appreciate any general notes on how to make the above code more efficient. Is it bad style to keep using "echo.. "? – May 03 '13 at 20:04