Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP link not appearing

Tags:

html

php

echo

I am trying to have the text "Facebook" to be a clickable link but for some reason it will not appear on the front-end.

Snippet of Code:

function friend_contact() {

$healthcard = get_field('healthcard');
$facebook = get_field('facebook');
$phone = get_field('phone');
$fax   = get_field('fax');
$email = get_field('email');

$post_info = '';

if (isset($healthcard['url'])) {
    $img = get_stylesheet_directory_uri() . "/images/mail-icon.png";
    $post_info .= '<a class="healthcard" href="'.$healthcard['url'].'"><img src="'.$img.'" /> Download Contact</a>';
}

if (isset($facebook['url']) && isset($healthcard['url']) {
    $post_info .= ' | ';
}   

if (isset($facebook['url'])) {
$post_info .= '<a href="'.$facebook['url'].'"><i class="fa fa-facebook" style="color:blue"></i> Facebook</a>';
}


$post_info .= '<ul class="friend-contact">';
$post_info .= "<li>$email</li>";
$post_info .= "<li>p: $phone</li>";
$post_info .= "<li>f: $fax</li>";
$post_info .= "</ul>";

var_dump($facebook);    
var_dump(get_field('facebook'));

genesis_markup( array(
    'html5' => sprintf( '<div class="entry-meta">%s</div>', $post_info ),
    'xhtml' => sprintf( '<div class="post-info">%s</div>', $post_info ),
) );
}

Results of Dump:

string(21) "https://www.yahoo.com" string(21) "https://www.yahoo.com"


enter image description here

Alternative Code With ['url']:

if (isset($facebook) && isset($healthcard['url']) {
    $post_info .= ' | ';
}

if (isset($facebook)) {
    $post_info .= '<a class="facebook" a href="$facebook"><i class="fa fa-facebook"></i> Facebook</a>';
    }

I think the root of the problem is with the code bit, ['url'] Thank you in advance

like image 434
Bob King Avatar asked Feb 22 '26 03:02

Bob King


1 Answers

You echo your string with single quotes, thus it won't process the variable. That looks like it's between double quotes, but that is part of your string. So either make it

$post_info .= '<a class="facebook" href="'.$facebook.'"><i class="fa fa-facebook"></i> Facebook</a>';

or reverse the quotes.

$post_info .= "<a class='facebook' href='$facebook'><i class='fa fa-facebook'></i> Facebook</a>";

Edit: as to what's the better way, is another discussion. As long as you're consistent.

like image 118
Francesco de Guytenaere Avatar answered Feb 23 '26 16:02

Francesco de Guytenaere



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!