I am using a WordPress plugin for custom fields.
the_field('something')
is, I pressume, just echoing the return value.
Is it not possible to store that return value into a variable?
because $a = the_field('something');
is also echoing.
What I really want to do is this
if(the_field('something')) {
// echo the_field('something')
}
else
// do something
but either way, it just echoes that thing in the page
As I said in my comment, If a function just echos something, then there is no return value. But there is still a way to capture the output.
Consider this function
You can’t get a return value from that, but you can capture the contents by using the ob_functions:
Now
$output
contains the output of that function, rather than it having been printed.WordPress I do not like. It seems that they have two functions (or more) for retrieving about anything. One echos it
the_title()
and the other returns itget_title()
. For this plugin this should work:If you run across something that echos and doesn’t return a value and no corresponding function that does return something, then: