PHP link not showing up
I'm trying to get the "Facebook" text to be a click-through link, but for some reason it won't appear in the interface.
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 ),
) );
}
Dump results:
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 has to do with a bit of code, ['url']
Thanks in advance
source to share
You are iterating over your single quoted string so it won't process the variable. It looks like double quotes, but it's part of your string. So either do this
$post_info .= '<a class="facebook" href="'.$facebook.'"><i class="fa fa-facebook"></i> Facebook</a>';
or undo the quotes.
$post_info .= "<a class='facebook' href='$facebook'><i class='fa fa-facebook'></i> Facebook</a>";
Edit: what's best, this is another discussion. As long as you agree.
source to share
It seems that you missed the 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 variable $facebook
is a string, so is $facebook['url']
invalid and isset($facebook['url'])
always returns false . So replace everything with $ facebook without the parentheses part.
If $healthcard
it is also a string and not an array, you must also replace $healthcard['url']
with $healthcard
.
source to share