I have a function like that
function get_file_size()
{
$size = '';
if (get_field('size') && get_field('megabyte')) :
$size = the_field('size');
the_field('megabyte');
endif;
return $size; //it return 20mb
}
my problem comes when I want to call the above function in theme.
$size_link = get_file_size();
$output = sprintf(
'<span >%2$s</span>',
esc_attr(join(' ', $classes)),
$size_link
);
the above code return
20mb20mb
<span></span>
by the way, when I try to like this
$output = sprintf(
'<span >%2$s</span>',
esc_attr(join(' ', $classes)),
get_file_size()
);
nothing print!
CodePudding user response:
It's because the_field
in your get_file_size
method prints the value, change these to get_field
instead.