# Block Links in WPForms Paragraph Fields

> Shows an error when a WPForms paragraph text field contains web links, which stops most link spam without adding a captcha.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: wpforms, spam, validation
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/wpforms-no-links-in-message/

## Code

```php
$wpide_wpf_max_links = 0;

add_action( 'wpforms_process_validate_textarea', function ( $field_id, $field_submit, $form_data ) use ( $wpide_wpf_max_links ) {
    $links = preg_match_all( '#(https?://|www\.|\[url|<a\s)#i', (string) $field_submit );

    if ( $links > $wpide_wpf_max_links ) {
        $process = method_exists( wpforms(), 'obj' ) ? wpforms()->obj( 'process' ) : wpforms()->process;
        $process->errors[ $form_data['id'] ][ $field_id ] = 0 === $wpide_wpf_max_links ? 'Please remove the links from your message.' : sprintf( 'Please include no more than %d link(s).', $wpide_wpf_max_links );
    }
}, 10, 3 );
```

## Notes

Set the number of links you allow at the top if customers often share a link.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Block Links in WPForms Paragraph Fields" 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/
