Ignore Words Inside Parentheses

Code

Filename: gpwc-word-count.php

<?php
/**
 * Gravity Perks // Word Count // Ignore Words Inside Parentheses
 * https://gravitywiz.com/documentation/gravity-forms-word-count/
 */
add_filter( 'gpwc_word_count', function( $word_count, $words ) {

	$words = preg_split( '/[ \n\r]+/', trim( preg_replace( '/\(([^)]+)\)/', '', $words ) ) );

	return count( $words );
}, 10, 2 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.