Remove Spaces Merge Tag Modifier

Use the “:remove_spaces” modifier to remove any spaces within a merge tag value.

Ideal for when using field values within a URL.

Example: {:1:remove_spaces}

Code

Filename: gw-merge-tag-modifier-remove-spaces.php

<?php
/**
 * Gravity Wiz // Gravity Forms // Remove Spaces Merge Tag Modifier
 * https://gravitywiz.com/
 *
 * Use the ":remove_spaces" modifier to remove any spaces within a merge tag value.
 *
 * Ideal for when using field values within a URL.
 *
 * Example: {:1:remove_spaces}
 */
add_filter( 'gform_merge_tag_filter', function( $value, $merge_tag, $modifier, $field_id ) {
  if ( ! rgblank( $value ) && $modifier === 'remove_spaces' ) {
    return str_replace( ' ', '', $value );
  }

  return $value;
}, 10, 4 );

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.