# Spam Comments Linking to Suspicious Domains

> Sends comments to spam when the commenter's website field points to a domain ending you have chosen to distrust, such as .xyz, .top or .click.

- Type: PHP
- Runs: Run everywhere
- Category: [Security](https://wpide.com/library/category/security/)
- Tags: comments, spam, links
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/comment-suspicious-website-tlds/

## Code

```php
$wpide_spam_tlds = array( 'xyz', 'top', 'click', 'loan', 'work', 'icu', 'buzz', 'cam', 'rest' );

add_filter( 'pre_comment_approved', function ( $approved, $commentdata ) use ( $wpide_spam_tlds ) {
    if ( 'spam' === $approved || empty( $commentdata['comment_author_url'] ) ) {
        return $approved;
    }

    $host = strtolower( (string) wp_parse_url( $commentdata['comment_author_url'], PHP_URL_HOST ) );
    $tld  = substr( strrchr( '.' . $host, '.' ), 1 );

    return in_array( $tld, $wpide_spam_tlds, true ) ? 'spam' : $approved;
}, 20, 2 );
```

## Notes

Edit the endings at the top to match the spam you actually receive.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Spam Comments Linking to Suspicious Domains" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
