Jump to content

function echos from inside an if statement and how do i find if exists


Recommended Posts

hello

 

im having a problem with my if statement in wordpress

 

the if is inside a function and includes another function.

 

if i do this

the_author_meta('linkedin', $author->ID);

 

it echos out a linkedin address: uk.linkedin.com/pub/andrew-adie/b/858/985@adiemoi

 

 

if have put it into a <a> tag to tidy it up

echo '<h5><a href="';
the_author_meta('linkedin', $author->ID);
echo '">Linkedin</h5>';

 

so now i get a link called linkedin.

 

i want the link to only appear if the function "the_author_meta('linkedin', $author->ID);" is not empty

so i tried this not im not sure if this is the correct way ???

 

if(the_author_meta('linkedin', $author->ID)){
echo '<h5><a href="';
the_author_meta('linkedin', $author->ID);
echo '">Linkedin</h5>';
}

 

also when i run this code i get this echoed out:

 

uk.linkedin.com/pub/andrew-adie/b/858/985@adiemoi

 

so it looks like its echoing the function from inside the if and the if is not working anyway because not getting any "Linkedin" links showing.

 

so how can i get it to only show Linkedin links if the exist ?

 

thanks

 

rick

You need to make the_author_meta() return it's data not echo it. If it is a built in Wordpress function, then it (like a lot of things in wordpress) is floored and you will need to find an alternative / hack the current implementation / write a wrapper capturing it's output into a buffer.

Looking at there docs, you should be using get_the_author_meta() instead.

 

if (get_the_author_meta('linkedin', $author->ID)) {
  echo '<h5><a href="' . get_the_author_meta('linkedin', $author->ID) . '">Linkedin</h5>';
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.