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"
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
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.
It seems that you missed a closing parenthesis in the following line:
if (isset($facebook['url']) && isset($healthcard['url']) {
Your code should look like this:
if ( isset($facebook['url']) && isset($healthcard['url']) ) {
Also the $facebook
variable is a string so $facebook['url']
is not valid and isset($facebook['url'])
returns always false. So replace everything with $facebook without the brackets part.
If $healthcard
is also a string and not an array then you should also replace $healthcard['url']
with $healthcard
.