WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Comments section outputting in plain html (15 posts)

  1. Feartheflame
    Member
    Posted 2 years ago #

    Hey guys,

    I'm hoping you can help me with a problem I seem to be having. The comments section on our website seems to be outputting any comment as plain html. This causes issues as there are no line breaks or anything. Not only that but it's also potentially a problem because of the freedom it gives anyone posting a comment.

    I've tried using the functions below to try and solve the issue but to no avail. If anyone could help fix the issue, that would be fantastic.

    The following code was placed in the functions.php file, but didn't help

    add_filter(‘comment_text’, ‘wp_filter_nohtml_kses’);
    add_filter(‘comment_text_rss’, ‘wp_filter_nohtml_kses’);
    add_filter(‘comment_excerpt’, ‘wp_filter_nohtml_kses’);

    An example of the comments section can be found at: http://www.lthan3.com/?p=315

    All I'm looking for is a simple fix to make comments be output in plain text, so if I type

    Line 1
    Line 2
    Line 3

    In a comment, it comes out as such, rather than Line 1 Line 2 Line 3.

    Thanks for any help provided <3

  2. SiRa-wp
    Member
    Posted 2 years ago #

    I think you'll have to supply the code for 'wp_filter_nohtml_kses'. Why don't you use the comment_form of WP though? Your commments don't look that much different...

  3. Feartheflame
    Member
    Posted 2 years ago #

    Hey Sira.

    The filter functions I had to find somewhere, I didn't set them, which might be why they're not actually applying anything.

    I could use comment_form but it's been so long I honestly wouldn't know what that requires, it's been years since any WP site I've had to use/make has had to worry about comments so I'm rusty in everything to do with them :P

    Any way you could guide me through it?

  4. SiRa-wp
    Member
    Posted 2 years ago #

    This is the comment form code explained with a link to a coded comment form.
    Otto's original guide for WordPress 2.7 comments http://ottopress.com/2008/wordpress-2-7-comments-enhancements

    But all you have got to do is clean up functions.php from this code of yours and than find your comment coding in index.php or wherever an replace it be <?php comment_form (); ?>

    http://codex.wordpress.org/Function_Reference/comment_form

  5. Feartheflame
    Member
    Posted 2 years ago #

    Sorry Sira. I must be having one of those days.

    I don't see where in the ottopress link it explains how to simply get comments output as plain text, nor do I see how comment_form will assist me in this.

  6. SiRa-wp
    Member
    Posted 2 years ago #

    The WP comment form looks like whatever you are using to display your comments at the moment. So you can use that, because it is build in and gives you the chance to get rid of code that seems buggy and not at all easy to maintain.

    I send you the additional information so you know how its coded and how to apply changes you want to make and the comment form does not output comments as plain txt, its formatted text, the way word and wordpress format text, with linebreaks and everything.

    Sorry I can't be of more help...

  7. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    what is the code used in comments.php?

    please use the pastebin for the code - see http://codex.wordpress.org/Forum_Welcome#Posting_Code

  8. Feartheflame
    Member
    Posted 2 years ago #

    @Alchymyth

    http://pastebin.com/PFt57fQc

    We've managed to fix the amount of freedom that people have in the comments section by changing the allowed html in kses.php, however it's still applying zero formatting to comments, so no linebreaks or anything, which is now the issue we're trying to solve.

  9. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    next step, continuing from this line:

    <?php wp_list_comments( array( 'callback' => 'fear_comment' ) );        ?>

    what is the code of the function fear_comment() which you might find in functions.php of your theme (?)

    this is likely to have the code which outputs the comment text.

  10. Feartheflame
    Member
    Posted 2 years ago #

    http://pastebin.com/bzqseL8Y

    That's all the info in the functions.php file relating to fear_comment()

  11. SiRa-wp
    Member
    Posted 2 years ago #

    It is the p class no-margin bottom in the div class comment_box that your changes are targeting, but aparantly that is not working. Where did you find these filters above, that you put in the functions php?

  12. Feartheflame
    Member
    Posted 2 years ago #

  13. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    in this line:

    <div class="comment_box"><p class="no_margin_bottom"><?php echo $comment->comment_content; ?></p></div><!-- #comment box -->

    try to replace <p class="no_margin_bottom"><?php echo $comment->comment_content; ?></p> with <?php comment_text(); ?>
    and try to create the 'no_margin_bottom' formatting (?) in some other ways (although removing this css class does not seem to make any difference);

    http://codex.wordpress.org/Function_Reference/comment_text

    or try to replace <p class="no_margin_bottom"><?php echo $comment->comment_content; ?></p> with <?php echo apply_filters('comment_text',$comment->comment_content); ?>
    with the same issue with the 'no_margin_bottom' formatting (?)

  14. Feartheflame
    Member
    Posted 2 years ago #

    <?php comment_text(); ?>

    Worked thanks Alchy, that solves a lot of issues, much appriciated!

  15. SiRa-wp
    Member
    Posted 2 years ago #

    I don't want to spoil this, but maybe you'd like to check, if your extra html is working, because the link you send above is about getting rid of html, not adding it, and comment_text comes with a lot of html options out of the box.

Topic Closed

This topic has been closed to new replies.

About this Topic