I have a question about php (wordpress) I have a plugin(buddypress) with function bp_the_profile_field_name();
when i use
echo bp_the_profile_field_name();
It’s return "Tags"
But..
if (bp_the_profile_field_name() == "Tags"){
echo "Yes, it's working";
} else {
echo "Oh no..";
}
?>
its return "Oh no.."
When i try equal to string "Tags" dosent’t match.
Why? Please help
2
Answers
When googling to the source of the
bp_the_profile_field_name
function I found this source:Here we can see that the
the
function usesecho
to show the value.If you want to get the value to compare it with something else you’ll need to use a other function which will return the value.
Below the mentioned page in the ‘related’ part this function is mentioned:
Note the
_get_
insteaf off_the_
Which returns a string. Source can be found here.
So your code should become:
According to documentation (https://www.buddyboss.com/resources/reference/functions/bp_the_profile_field_name/) bp_the_profile_field_name() echoes output.
If you want to compare the output of this function you need a return, not echo.
You have 2 options: