I want to create a plugin to sanitize comment and mainly the url field before display only (not before adding to database), to filter the url fields and only allow displaying this field only if it contains specific data, otherwise I want to replace this url field with something safe or clear it.

( i do not want users to enter the url as "test.com" or "example.com" , i want to remove it in these cases)

How can I do that, which filter do i need to add to ?


based on the selected answer, I created this plugin to reset all urls to empty strings:

Plugin Name: Get rid of websites before display
function my_custom_remove_website( $comments ) {
    foreach ($comments as $k => $comment) {
        $comments[$k]->comment_author_url = "";
    return $comments;
add_filter( 'comments_array', 'my_custom_remove_website' );

Please feel free to comment or answer if this plugin is not done with best practices.


You might want to check out the comments_array filter.

In 3.5, it is applied in Line 891 of wp-includes/comment-template.php:
$wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );

| improve this answer | |
  • Thanks, it worked, I created a plugin based on your input, I posted it above in my question, please feel free to comment if there is something wrong in the plugin I made. – sharp12345 Mar 12 '13 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.