whats app web custom field for the phone

1

I want to add in PHP the href of the whats app link and the phone number to complete it with a custom field. I call it $ tel. I can not get it, I get the following error, can you help me? Is it okay?

<?php
$tel = get_field('telefono');
var_dump($tel);


if( $tel ): ?>

<a class="button" href="<?php echo http://api.whatsapp.com/send?phone=$tel;?>">Enviar Whats App</a>  // line 153 

<?php endif; ?>
  

Parse error: syntax error, unexpected ':', expecting ',' or ';' in   /home/c1300927/public_html/home/wp-content/themes/startit/startit/single.php   online 153 (yellow)

    
asked by Jennifer 06.09.2018 в 04:09
source

1 answer

1

Another way to do it, and that will avoid the horrible mixture of PHP / HTML code that produces a code that does badly in sight, would concatenate a single variable and print it at the end.

This will prevent the constant opening / closing of PHP blocks that make the code really difficult to analyze. Here everything is done within a single block of PHP code.

<?php

$tel = get_field('telefono');
$html=""; //Vamos a concatenar con esta variable
if( $tel ) {
    $html.='<a class="button" href="http://api.whatsapp.com/send?phone='.$tel.'">Enviar Whats App</a>';
}else{
    $html.="No tiene teléfono"; //Esto es opcional
} 
echo $html;

?>
    
answered by 06.09.2018 / 04:32
source