Support » Fixing WordPress » Force a function to produce a custom HTML code

  • Resolved WHiSPER



    I use comment_text() function in a while loop to list comments in my theme. By default this function produce a <p> tag with the comment text in it.

    Now, I want to ask is there any way to add an id to the HTML element <p>?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer


    Try it with get_comment_text() [untested]

    echo '<p id="comment-text">' . get_comment_text() . '</p>';



    Forum Moderator

    unless that css id is dependant on the individul comment, you should rather use a css class;

    because comment_text() uses a filter for the output:

    echo apply_filters( 'comment_text', get_comment_text( $comment_ID ), $comment );

    you can try adding a filter function to functions.php, to be able to influence the html paragraph tag;

    example to add a css class to the first paragraph tag in the comment text(untested):

    function adapt_html_comment_text($text) {
    $text = preg_replace( '/\<p/', '<p class="comment-text"', $text, 1 );
    return $text;

    details will depend on what exactly you want to add to the p tag.

    Worked! Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Force a function to produce a custom HTML code’ is closed to new replies.