{embed_url} but strip domain [RESOLVED]

Hello,

we are using {embed_url} in a hidden field, however i want to strip the URL so it only shows the slug after
eg, if domain is https://www.domains.com.org/urlstogo/hello1 it will only show /urlstogo/hello1

Is there a way to do this, and also have it work for email routing, so i also dont have to put the entire URL in the routing section?

Hi Bobby. I recommend using the gform_field_value filter:

  1. For the field you want to store the slug in, check the box to “allow field to be populated dynamically” and give it the parameter name slug.
  2. Add this code to the site to grab the permalink, then extract the slug and store it in the field:
add_filter( 'gform_field_value_slug', 'populate_slug' );
function populate_slug( $value ) {
    global $post;
    GFCommon::log_debug( __METHOD__ . '(): The Post => ' . print_r( $post, true ) );
    $permalink = get_permalink( $post );
    $parsed_url = parse_url( $permalink );
    GFCommon::log_debug( __METHOD__ . '(): The Parsed URL => ' . print_r( $parsed_url, true ) );
    return $parsed_url['path'];
}

You can remove the merge tag {embed_url} from the default value for the field. This code will handle populating the field with the slug. Because that is done when the form is first loaded, you can base routing or conditional logic on that field.

Let us know if you need any other assistance.

1 Like

this is perfect!

1 Like