Trying to connect to the comment_text () function provided by the Wordpress API to wrap the output of each comment in a container, <div>...</div>I encountered the following problem:
Without my extra filter, the output of comment_text () looks like this:
<p>Hello User!</p>
<p>Thank you for your comment.</p>
<p>Stefan</p>
OK, but as I said, I would like it to be wrapped in <div class="comment-text">...</div>. As far as I know, the correct way to do this is to add a filter to functions.phpmy topic, and so I did:
function stefan_wrap_comment_text($content) {
return "<div class=\"comment-text\">". $content ."</div>";
}
add_filter('comment_text', 'stefan_wrap_comment_text');
As I can see in the output, this filter works, but it has a negative effect on the first paragraph of the content, as you can see in the following example. The first paragraph should be <p>Hello User!</p>, but it looks like this: Hello User!.
<div class="comment-text">
Hello User!
<p>Thank you for your comment.</p>
<p>Stefan</p>
</div>
Any ideas or hints on what I'm doing wrong?
source
share