Trying to hook into the function comment_text() supplied by WordPress API to wrap the output of every comment into a <div>...</div>
container I am running into the following problem:
Without my added filter the output of comment_text() looks like this:
<p>Hello User!</p>
<p>Thank you for your comment.</p>
<p>Stefan</p>
Thats fine but as I said I would like to have it wrapped into a <div class="comment-text">...</div>
. As far as I know the correct way doing this would be in adding a filter to functions.php
of my theme 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 from the output the given filter works but it has a negative sideeffect to the first paragraph of the content as you can see in the following example. The first paragraph should be <p>Hello User!</p>
but 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 what I am doing wrong?
Try to lower the priority of your function, maybe there is some formatting function which you precede.
Ouch, just stumbled over the file
wp-includes/default-filters.php
and found out that there are several filters applied to the same function per default:The last filter with priority 30 calls the function wpautop() that is used for replacing double line breaks with
<p>...</p>
. Per default add_filter() registers new filters on priority 10. Changing my filter to be the last by choosing a higher number everything works fine.