• Resolved Tzeapa

    (@tzeapa)


    Hello,

    All my comments look extremely stuffed because WordPress replaces empty lines (as in Enter/Return pressed 2 times) with <br/>.

    For some ridiculous reason <br/> tags don’t work. <br> works just fine.

    All I need to do is stop WordPress from replacing blank spaces with <br/> and instead making it replacing it with <br>.

    I tried passing comment-text() into a variable and did a str_replace on that and then finally echoed the variable but it didn’t work (I’m no PHP guru).

    Removing wpautop didn’t work either. Added a tag from mysql but that got replaced with a <br/> tag in HTML.

    This is not plugin or theme related as I tried multiple themes and disabled all plugins to no avail…

    Is there a solution for this?

    Regards.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    For some ridiculous reason <br/> tags don’t work. <br> works just fine.

    That sounds a bit weird. When I press enter twice, my lines get

    <p>Some text here</p>
    <p>Some more text here</p>

    Can you share a link with us?

    Thread Starter Tzeapa

    (@tzeapa)

    Double Enter gets replaced with <p></p> only in the post, in the comments it gets replaced with <br/>

    link: http://bit.ly/q2CnMQ

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    I believe you, but I tried it on my Crash Test Dummy blog and left a comment. Just as you’ve described I pressed enter/return twice to separate the lines.

    The comment was formatted with lines wrapped in <p> and </p>. That’s why I asked about a link so I can take a close look and see if it’s theme related.

    Thread Starter Tzeapa

    (@tzeapa)

    I posted the link…http://bit.ly/q2CnMQ

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    DOH! So you did. Looking…

    The comments seem to be wrapped in <p> and </p>. Look at your blog’s comment ID 2211.

    http://your-blog-url/wp-admin/comment.php?action=editcomment&c=2211

    The plain editor should show the lines but if you look at that comment’s source, it’s not using <br>.

    Can you post a link to a comment where I can see the <br> in the HTML?

    Thread Starter Tzeapa

    (@tzeapa)

    http://bit.ly/qa5Xcu
    Look at the first comment here and check the HTML and find this line:

    <br/> Now the person he is told

    The comment has no blank lines…

    Edit: Don’t the comments look too cluttered to you? If Enter twice I’d like to see the free line spacing, in mysql the line is showing…

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Found it, thanks. That’s bizarre. I wasn’t able to reproduce it but there it is and I don’t know what’s causing it.

    When you edit the comment, the <br/> isn’t there, so that’s not something that can be filtered with comment_text. It may be an applied filter.

    In the wp-includes/default-filters.php comment_text get’s these filters

    add_filter( 'comment_text', 'wptexturize'            );
    add_filter( 'comment_text', 'convert_chars'          );
    add_filter( 'comment_text', 'make_clickable',      9 );
    add_filter( 'comment_text', 'force_balance_tags', 25 );
    add_filter( 'comment_text', 'convert_smilies',    20 );
    add_filter( 'comment_text', 'wpautop',            30 );

    You’ve ruled out wpautop and I think it may be convert_chars.

    Try this: in wp-content/plugins/ create a file called comment-filter-remove.php and put in these lines

    <?php
    /*
    Plugin Name: Remove Comment Filters
    */
    
    // remove_filter( 'comment_text' , 'wptexturize' );
    remove_filter( 'comment_text' , 'convert_chars' );
    // remove_filter( 'comment_text' , 'make_clickable', 9 );
    // remove_filter( 'comment_text' , 'force_balance_tags', 25 );
    // remove_filter( 'comment_text' , 'convert_smilies', 20 );
    // remove_filter( 'comment_text' , 'wpautop' , 30 );

    If that works from the start, then it’s convert_chars.

    If that doesn’t work, you can comment out the convert_chars by adding // in front of that line. Un-comment out one of the other lines to find it.

    It might be convert_smilies but that would be surprising…

    If something bad happens, just delete the new plugin comment-filter-remove.php.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Edit: Don’t the comments look too cluttered to you?

    Yep, that’s cluttered alright. πŸ™‚

    Thread Starter Tzeapa

    (@tzeapa)

    Thanks for the involvement but those nasty <br/> are still there…

    Removed the comment from all lines, tried them individually but there is no change.

    I had a million trillion issues with WP and always managed to work around them, this one seems a bit impossible…

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Wait, is the <br/> is stored in the database? I mean, when you look at the comment in the edit screen or database, you see <br/> in the comment text?

    If that’s the case, give this a shot.

    Create in wp-content/plugins a new plugin file called remove-br.php and put this in there.

    <?php
    /*
    Plugin Name: Remove br from comment_text
    */
    
    add_filter( 'comment_text' , 'mh_remove_br' , 99 );
    function mh_remove_br( $text ) {
       return str_replace( '<br/>' , '<p />' , $text );
    }

    That will replace the <br/> with <p /> and hopefully will space out the comment text. It won’t actually change it in the database, it will make the substitution when the comments are being displayed.

    If that actually does work you can style the p with line height, margin, padding, etc. I don’t think you can use CSS on br without pain.

    Thread Starter Tzeapa

    (@tzeapa)

    When I edit the comment in mysql or in WP editor I don’t see any <br/> BUT if I enter a <br> tag while writing a comment that becomes <br/> <br/> (one br tag becomes 2 br tags…) and a free line appears after you submit the comment.

    I guess I’ll add a top-padding to comment <p> and that should do the trick.

    Thanks for your help !

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Your welcome, wish I’d though to suggest CSS a few hours ago! πŸ™‚

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Stop WordPress from replacing BR tag’ is closed to new replies.