ricky spires Posted February 5, 2013 Share Posted February 5, 2013 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 Link to comment https://forums.phpfreaks.com/topic/274053-function-echos-from-inside-an-if-statement-and-how-do-i-find-if-exists/ Share on other sites More sharing options...
trq Posted February 5, 2013 Share Posted February 5, 2013 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. Link to comment https://forums.phpfreaks.com/topic/274053-function-echos-from-inside-an-if-statement-and-how-do-i-find-if-exists/#findComment-1410192 Share on other sites More sharing options...
PFMaBiSmAd Posted February 5, 2013 Share Posted February 5, 2013 Quote NOTE: Use get_the_author_meta() if you need to return (not display) the information. Link to comment https://forums.phpfreaks.com/topic/274053-function-echos-from-inside-an-if-statement-and-how-do-i-find-if-exists/#findComment-1410193 Share on other sites More sharing options...
trq Posted February 5, 2013 Share Posted February 5, 2013 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>'; } Link to comment https://forums.phpfreaks.com/topic/274053-function-echos-from-inside-an-if-statement-and-how-do-i-find-if-exists/#findComment-1410194 Share on other sites More sharing options...
ricky spires Posted February 5, 2013 Author Share Posted February 5, 2013 thanks . ill give it a try Link to comment https://forums.phpfreaks.com/topic/274053-function-echos-from-inside-an-if-statement-and-how-do-i-find-if-exists/#findComment-1410208 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.