Title: Force a function to produce a custom HTML code
Last modified: August 20, 2016

---

# Force a function to produce a custom HTML code

 *  Resolved [WHiSPER](https://wordpress.org/support/users/apc_whisper/)
 * (@apc_whisper)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/force-a-function-to-produce-a-custom-html-code/)
 * Hi,
 * 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](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/force-a-function-to-produce-a-custom-html-code/#post-3152415)
 * Try it with get_comment_text() [untested]
 *     ```
       <?php
       echo '<p id="comment-text">' . get_comment_text() . '</p>';
       ?>
       ```
   
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/force-a-function-to-produce-a-custom-html-code/#post-3152419)
 * 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):
 *     ```
       add_filter('comment_text','adapt_html_comment_text',30);
       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.
 *  Thread Starter [WHiSPER](https://wordpress.org/support/users/apc_whisper/)
 * (@apc_whisper)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/force-a-function-to-produce-a-custom-html-code/#post-3152422)
 * **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.

## Tags

 * [comment_text](https://wordpress.org/support/topic-tag/comment_text/)
 * [edit function](https://wordpress.org/support/topic-tag/edit-function/)
 * [function](https://wordpress.org/support/topic-tag/function/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [WHiSPER](https://wordpress.org/support/users/apc_whisper/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/force-a-function-to-produce-a-custom-html-code/#post-3152422)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
