WP 5.4 Theme masonic
I try to show the numer of comments in each article it'as ok (see the picture) but on the next line, itshow ()
I don't know why !?!?
the code in the file template-tags is:
echo '<div class="entry-author vcard author fa fa-user"><a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></div>';
// Show number of comments
echo '<div>(' . comments_number( '(0) ', '(1)', '(%)' ) . ')</div>';
WP 5.4 Theme masonic
I try to show the numer of comments in each article it'as ok (see the picture) but on the next line, itshow ()
I don't know why !?!?
the code in the file template-tags is:
echo '<div class="entry-author vcard author fa fa-user"><a class="url fn n" href="' . esc_url(get_author_posts_url(get_the_author_meta('ID'))) . '">' . esc_html(get_the_author()) . '</a></div>';
// Show number of comments
echo '<div>(' . comments_number( '(0) ', '(1)', '(%)' ) . ')</div>';
Share
Improve this question
edited Apr 27, 2020 at 7:24
Jacob Peattie
44.2k10 gold badges50 silver badges64 bronze badges
asked Apr 27, 2020 at 7:18
pascalnivpascalniv
1
1 Answer
Reset to default 0There's two issues at play here.
First, you've got two sets of parentheses:
↓ Here ↓ And Here
echo '<div>(' . comments_number( '(0) ', '(1)', '(%)' ) . ')</div>';
You only want one.
Second, you're trying to concatenate a string (.
) with a function, comments_number()
, that echoes. This results in comments_number()
being outut immediately, and then the rest of the string outputting after that. This is where the second ()
comes from.
To fix the issue, either remove echo
and output like this:
comments_number( '<div>(0)</div>div>', '<div>(1)</div>div>', '<div>(%)</div>div>' ) . ');
Or use get_comments_number_text()
which returns the same value:
echo '<div>(' . get_comments_number_text( '0', '1', '%' ) . ')</div>';
Note that I've also removed the redundant parentheses.