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 />";
}
?>
you should add
http://
on the beggining to make external URLSor add
http://
on your advanced custom field in the adminEDIT:
here is your final code:
NOTE:
wwww.facebook.com
has excess whttp://
is present, thanks to @feeela