简体   繁体   中英

PHP mailto: variable with faicon inline

this code is suppose to see if the ACF variable is empty if not prints html code of globe fa icon with mailto: variable called mail yet its not working any ideas?


<?php 
if((the_field('Email'))!=""){
    $mail = the_field('Email');
   echo '<a href="mailto:'.$mail.'"><i class="fa fa-envelope-o fa-2x"></i></a>'; 
}
?>

It is the basic thing there is the difference between get_field and the_field.

the_field print the data and get_field required echo to print the value. Assuming the meta key name is Email. Use below code

  <?php 
if(get_field('Email')!=""){
    $mail = get_field('Email');
   echo '<a href="mailto:'.$mail.'"><i class="fa fa-envelope-o fa-2x"></i></a>'; 
}
?>

I don't quite get the question but can you try:

<?php 
if((the_field('Email'))!=""){
    $mail = the_field('Email');
   echo '<a href="mailto:'.$mail.'"><i class="fa fa-envelope-o fa-2x">'.$mail.'</i></a>'; 
}
?>

如我所见,the_field是一个函数,此函数返回一个邮件字符,因此有关the_fileld('email')的返回值为Null,我认为这意味着您的问题出在此函数中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM