'function not call on the right html tag
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 class="%1$s">%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 class="%1$s">%2$s</span>',
esc_attr(join(' ', $classes)),
get_file_size()
);
nothing print!
Solution 1:[1]
It's because the_field in your get_file_size method prints the value, change these to get_field instead.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | naamhierzo |
